-
Notifications
You must be signed in to change notification settings - Fork 26
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
Pointers to nonheap objects can be passed to free in C #1237
Comments
Indeed we currently do not keep track of the origin of pointers. We should look at how other verifiers do this. For example in VeriFast you can have: #include <stdlib.h>
void foo(int a)
//@ requires true;
//@ ensures true;
{}
void test(int *a)
//@ requires integer(a, _) &*& malloc_block_ints(a, 1);
//@ ensures true;
{
foo(*a);
free(a);
} where In ACSL (Frama-C) there are separate allocation clauses to describe the behaviour of a function as described in the ACSL Manual paragraph 2.7.3:
I think I would prefer the simplicity of the VeriFast approach here. I don't think we'd have much benefit from keeping track of whether certain addresses are "allocable" since we don't reason about addresses anyway. (Frama-C basically just keeps track of a map from addresses to values to implement their pointers whereas we use Viper's fields) |
This is actually the point of blocks: it is intended that free requires something like:
I think this is in fact based on |
The following C program verifies:
However, its behavior is undefined - p is a pointer to a
foo
, but it doesn't point to memory allocated bymalloc
. In practice, on my machine, this aborts:The
TrivialAddrOf
rewriter seems to understand the line indicated//
as "create a new one-element pointer array (on the heap) and assign a value into it", but that fictional array does not exist in the actual program,p
is "just" the address ofthing
.The text was updated successfully, but these errors were encountered: