Skip to content

Commit 4a095a2

Browse files
committed
Null-pointer filtering must handle unknown offsets
A non-constant offset is stored as "unknown," which does include an offset of zero. As constant + zero == constant we should not conclude that the constant is not contained in the set.
1 parent fef6d08 commit 4a095a2

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

regression/cbmc/null7/main.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdlib.h>
2+
3+
_Bool nondet_bool();
4+
5+
int main()
6+
{
7+
char *s = NULL;
8+
char A[3];
9+
_Bool s_is_set = 0;
10+
11+
if(nondet_bool())
12+
{
13+
s = A;
14+
s_is_set = 1;
15+
}
16+
17+
if(s_is_set)
18+
{
19+
unsigned len;
20+
__CPROVER_assume(len < 3);
21+
s += len;
22+
}
23+
24+
if(s)
25+
*s = 42;
26+
27+
return 0;
28+
}

regression/cbmc/null7/test.desc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE broken-smt-backend
2+
main.c
3+
--pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
The value set may contain the constants with unknown offsets. Such cases cannot
11+
be conclusively filtered out as the offset may be zero.

src/goto-symex/symex_goto.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ static optionalt<renamedt<exprt, L2>> try_evaluate_pointer_comparison(
114114
value_set_element.id() == ID_unknown ||
115115
value_set_element.id() == ID_invalid ||
116116
is_failed_symbol(
117-
to_object_descriptor_expr(value_set_element).root_object()))
117+
to_object_descriptor_expr(value_set_element).root_object()) ||
118+
to_object_descriptor_expr(value_set_element).offset().id() == ID_unknown)
118119
{
119120
// We can't conclude anything about the value-set
120121
return {};

0 commit comments

Comments
 (0)