-
Notifications
You must be signed in to change notification settings - Fork 274
Use OBJECT_SIZE(p) for dynamic memory bounds checking #5247
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
void main() | ||
{ | ||
char c[2]; | ||
assert(__CPROVER_r_ok(c, 2)); | ||
assert(!__CPROVER_r_ok(c, 2)); | ||
assert(__CPROVER_r_ok(c, 3)); | ||
assert(!__CPROVER_r_ok(c, 3)); | ||
|
||
char *p = malloc(2); | ||
assert(__CPROVER_r_ok(c, 2)); | ||
assert(!__CPROVER_r_ok(c, 2)); | ||
assert(__CPROVER_r_ok(p, 3)); | ||
assert(!__CPROVER_r_ok(p, 3)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CORE | ||
main.c | ||
|
||
\[main.assertion.1\] .*: SUCCESS | ||
\[main.assertion.2\] .*: FAILURE | ||
\[main.assertion.3\] .*: FAILURE | ||
\[main.assertion.4\] .*: SUCCESS | ||
\[main.assertion.5\] .*: SUCCESS | ||
\[main.assertion.6\] .*: FAILURE | ||
\[main.assertion.7\] .*: FAILURE | ||
\[main.assertion.8\] .*: SUCCESS | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
void main() | ||
{ | ||
char *p; | ||
int choice; | ||
|
||
if(choice) | ||
{ | ||
p = malloc(2); | ||
} | ||
else | ||
{ | ||
p = malloc(3); | ||
} | ||
|
||
assert(__CPROVER_r_ok(p, 2)); | ||
assert(!__CPROVER_r_ok(p, 2)); | ||
|
||
assert(__CPROVER_r_ok(p, 3)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice - not obvious so good to check it works |
||
assert(!__CPROVER_r_ok(p, 3)); | ||
|
||
assert(__CPROVER_r_ok(p, 4)); | ||
assert(!__CPROVER_r_ok(p, 4)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CORE broken-smt-backend | ||
main.c | ||
|
||
\[main.assertion.1\] .*: SUCCESS | ||
\[main.assertion.2\] .*: FAILURE | ||
\[main.assertion.3\] .*: FAILURE | ||
\[main.assertion.4\] .*: FAILURE | ||
\[main.assertion.5\] .*: FAILURE | ||
\[main.assertion.6\] .*: SUCCESS | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
This test checks that __CPROVER_r_ok() gives the correct result when the given | ||
pointer can point to different memory segments of different sizes |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <assert.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
int main() | ||
{ | ||
size_t x; | ||
size_t y; | ||
uint8_t *a; | ||
|
||
__CPROVER_assume(x > 0); | ||
__CPROVER_assume(y > x); | ||
|
||
a = malloc(sizeof(uint8_t) * x); | ||
|
||
assert(__CPROVER_w_ok(a, x)); | ||
assert(!__CPROVER_w_ok(a, y)); | ||
thk123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
main.c | ||
|
||
\[main.assertion.1\] .*: SUCCESS | ||
\[main.assertion.2\] .*: SUCCESS | ||
VERIFICATION SUCCESSFUL | ||
thk123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
This test checks that __CPROVER_r_ok() works with nondet sizes |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
int main() | ||
{ | ||
int *x = malloc(2); | ||
int *y = malloc(2); | ||
assert(!__CPROVER_r_ok(x, 3)); | ||
assert(__CPROVER_r_ok(x, 3) == __CPROVER_r_ok(y, 3)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Not sure I understand the purpose of the test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was reported in issue #5194. It checks that two uses of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Please add to the desc file 🙂 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CORE | ||
main.c | ||
|
||
\[main.assertion.1\] .*: SUCCESS | ||
\[main.assertion.2\] .*: SUCCESS | ||
VERIFICATION SUCCESSFUL | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
thk123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-- | ||
This test checks that two usages of the primitive __CPROVER_r_ok() can be false | ||
simultaneously in the encoding of the program. Previously, at most one call | ||
could be false at a time. This was imprecise, however, it was sufficient to | ||
guarantee soundness when the __CPROVER_r_ok() primitive was used directly in an | ||
assertion (i.e., as assert(__CPROVER_r_ok(p, size)). See issue #5194. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Still missing an explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one is simple enough to not need an explanation