Skip to content

array_set: do not fail upon an invalid (void) pointer #8202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions regression/cbmc/Array_operations3/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int main()
{
void *p;
__CPROVER_array_set(p, 0);
__CPROVER_assert(
*(char *)p == 0, "should fail: array_set had no effect on invalid object");
}
11 changes: 11 additions & 0 deletions regression/cbmc/Array_operations3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c

^\[main.assertion.1\] line 5 should fail: array_set had no effect on invalid object: FAILURE$
^VERIFICATION FAILED$
^EXIT=10$
^SIGNAL=0$
--
^warning: ignoring
--
An array_set on an invalid pointer must not result in an invariant failure.
5 changes: 5 additions & 0 deletions src/goto-symex/symex_other.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ void goto_symext::symex_other(
// obtain the actual array(s)
process_array_expr(state, array_expr);

// if we dereferenced a void pointer, we may get a zero-sized (failed)
// object -- nothing to be assigned
if(array_expr.type().id() == ID_empty)
return;

// prepare to build the array_of
exprt value = clean_expr(code.op1(), state, false);

Expand Down