Skip to content

Commit 25b4846

Browse files
committed
Contracts test: ensure return value access is in bounds
We ended up with an assumption that performed an out-of-bounds access as there was no link between `size` and the return value in the contract.
1 parent 7f2dd64 commit 25b4846

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

regression/contracts/assigns-replace-malloc-zero/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ __CPROVER_requires(0 <= size && size <= __CPROVER_max_malloc_size)
88
__CPROVER_requires(a == NULL || __CPROVER_rw_ok(a, size))
99
__CPROVER_assigns(__CPROVER_object_whole(a))
1010
__CPROVER_ensures(
11-
a && __CPROVER_return_value >= 0 ==> a[__CPROVER_return_value] == 0)
11+
a && __CPROVER_return_value >= 0 ==>
12+
(__CPROVER_return_value < size && a[__CPROVER_return_value] == 0))
1213
// clang-format on
1314
{
1415
if(!a)

regression/contracts/assigns-replace-malloc-zero/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ main.c
44
^\[foo.precondition.\d+\] line \d+ Check requires clause of foo in main: SUCCESS$
55
^EXIT=0$
66
^SIGNAL=0$
7-
\[main\.assertion\.1\] line 35 expecting SUCCESS: SUCCESS$
7+
\[main\.assertion\.1\] line 36 expecting SUCCESS: SUCCESS$
88
^VERIFICATION SUCCESSFUL$
99
--
1010
This test checks that objects of size zero or of __CPROVER_max_malloc_size

0 commit comments

Comments
 (0)