-
Notifications
You must be signed in to change notification settings - Fork 274
Verify that pointers used in pointer primitives are either null or valid #5318
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
danpoe
merged 1 commit into
diffblue:develop
from
danpoe:feature/pointer-primitive-check
Apr 23, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
void main() | ||
{ | ||
// we need a new variable for each check, as goto_checkt removes redundant | ||
// assertions, and if we would use the same variable all pointer primitive | ||
// assertions would look the same | ||
|
||
char *p1; | ||
__CPROVER_same_object(p1, p1); | ||
|
||
char *p2; | ||
__CPROVER_POINTER_OFFSET(p2); | ||
|
||
char *p3; | ||
__CPROVER_POINTER_OBJECT(p3); | ||
|
||
char *p4; | ||
__CPROVER_OBJECT_SIZE(p4); | ||
|
||
char *p5; | ||
__CPROVER_r_ok(p5, 1); | ||
|
||
char *p6; | ||
__CPROVER_w_ok(p6, 1); | ||
|
||
char *p7; | ||
__CPROVER_DYNAMIC_OBJECT(p7); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CORE | ||
main.c | ||
--pointer-primitive-check | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
\[main.pointer_primitives.1\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OBJECT.*: FAILURE | ||
\[main.pointer_primitives.2\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OFFSET.*: FAILURE | ||
\[main.pointer_primitives.3\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OBJECT.*: FAILURE | ||
\[main.pointer_primitives.4\] line \d+ pointer in pointer primitive is neither null nor valid in OBJECT_SIZE.*: FAILURE | ||
\[main.pointer_primitives.5\] line \d+ pointer in pointer primitive is neither null nor valid in R_OK.*: FAILURE | ||
\[main.pointer_primitives.6\] line \d+ pointer in pointer primitive is neither null nor valid in W_OK.*: FAILURE | ||
\*\* 7 of \d+ failed | ||
-- | ||
^warning: ignoring | ||
-- | ||
Verifies that checks are added for all pointer primitives |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdlib.h> | ||
|
||
char *p1; | ||
|
||
void main() | ||
{ | ||
__CPROVER_POINTER_OBJECT(p1); | ||
|
||
char *p2 = NULL; | ||
__CPROVER_POINTER_OBJECT(p2); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
main.c | ||
--pointer-primitive-check | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Verifies that a null pointer does not fail the pointer primitives check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <stdlib.h> | ||
|
||
void main() | ||
{ | ||
// uninitialized pointer | ||
char *p1; | ||
__CPROVER_POINTER_OBJECT(p1); | ||
|
||
// special value of invalid pointer | ||
char *p2 = (size_t)1 << (sizeof(char *) * 8 - 8); | ||
__CPROVER_POINTER_OBJECT(p2); | ||
|
||
// pointer object 123, offset 123, not pointing to valid memory | ||
char *p3 = ((size_t)123 << (sizeof(char *) * 8 - 8)) | 123; | ||
__CPROVER_POINTER_OBJECT(p3); | ||
|
||
// negative offset | ||
char *p4 = malloc(1); | ||
p4 -= 1; | ||
__CPROVER_POINTER_OBJECT(p4); | ||
|
||
// offset out of bounds | ||
char *p5 = malloc(10); | ||
p5 += 10; | ||
__CPROVER_POINTER_OBJECT(p5); | ||
|
||
// dead | ||
char *p6; | ||
{ | ||
char c; | ||
p6 = &c; | ||
} | ||
__CPROVER_POINTER_OBJECT(p6); | ||
*p6; | ||
|
||
// deallocated | ||
char *p7 = malloc(1); | ||
free(p7); | ||
__CPROVER_POINTER_OBJECT(p7); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CORE | ||
main.c | ||
--pointer-primitive-check | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
\[main.pointer_primitives.1\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OBJECT.*: FAILURE | ||
\[main.pointer_primitives.2\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OBJECT.*: FAILURE | ||
\[main.pointer_primitives.3\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OBJECT.*: FAILURE | ||
\[main.pointer_primitives.4\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OBJECT.*: FAILURE | ||
\[main.pointer_primitives.5\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OBJECT.*: FAILURE | ||
\[main.pointer_primitives.6\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OBJECT.*: FAILURE | ||
\[main.pointer_primitives.7\] line \d+ pointer in pointer primitive is neither null nor valid in POINTER_OBJECT.*: FAILURE | ||
\*\* 7 of \d+ failed | ||
-- | ||
^warning: ignoring | ||
-- | ||
Verifies that the pointer primitives check fails for the various forms of | ||
invalid pointers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
void main() | ||
{ | ||
char *p; | ||
__CPROVER_assume(__CPROVER_r_ok(p, 1)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
main.c | ||
--pointer-primitive-check | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
\[main.pointer_primitives.1\] line \d+ pointer in pointer primitive is neither null nor valid in R_OK.*: FAILURE | ||
\*\* 1 of \d+ failed | ||
-- | ||
^warning: ignoring | ||
-- | ||
Verifies that the check fails for a primitive in an assume that uses an | ||
uninitialized pointer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
⛏️ unnecessary blank line