Skip to content

Commit 21622a9

Browse files
committed
History variables do not check for nullness
Signed-off-by: Felipe R. Monteiro <[email protected]>
1 parent a80b65a commit 21622a9

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdlib.h>
2+
3+
struct pair
4+
{
5+
int x;
6+
int y;
7+
};
8+
9+
void foo(struct pair *p) __CPROVER_assigns(p->y)
10+
__CPROVER_ensures((p != NULL) == > (p->y == __CPROVER_old(p->y) + 5))
11+
__CPROVER_ensures((p == NULL) == > (p->y == __CPROVER_old(p->y)))
12+
{
13+
if(p != NULL)
14+
p->y = p->y + 5;
15+
}
16+
17+
int main()
18+
{
19+
struct pair *p = NULL;
20+
foo(p);
21+
22+
return 0;
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
KNOWNBUG
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[postcondition.\d+\] Check ensures clause\: SUCCESS$
7+
^\[foo.\d+\] line \d+ Check that p\-\>y is assignable\: SUCCESS$
8+
^VERIFICATION SUCCESSFUL$
9+
--
10+
--
11+
This test checks that history variables handle NULL pointers.
12+
History variables currently do not check for nullness while
13+
storing values of objects, which may lead to NULL pointer dereferences.

src/goto-instrument/contracts/contracts.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ void code_contractst::replace_old_parameter(
394394

395395
const auto &parameter = to_old_expr(expr).expression();
396396

397-
// TODO: generalize below
398397
if(
399398
parameter.id() == ID_dereference || parameter.id() == ID_member ||
400399
parameter.id() == ID_symbol)

0 commit comments

Comments
 (0)