-
Notifications
You must be signed in to change notification settings - Fork 88
Recognize pointers wrapped in TNamed in memOutOfBounds and fix bit-to-byte comparison bug
#1676
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
61120e8
Add regression test for memOutOfBounds analysis
karoliineh 5863af4
Recognize ptrs within `TNamed` as pointers in `memOutOfBounds`
karoliineh 5a1e695
Subtract one from nr of bytes only for comparison but not for printin…
karoliineh bf0050b
BugFix: convert bits to bytes to compare with another value of bytes
karoliineh 02678f4
Remove `--set exp.architecture 32bit` from regression test
karoliineh 7329091
Add regtest for named pointer comparison
karoliineh 7bb50c1
Unroll type in `is_statically_safe_cast`
karoliineh 1941b2b
Update tests/regression/01-cpa/76-pointer-typedef.c
karoliineh 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // PARAM: --set ana.malloc.unique_address_count 2 | ||
| // Extracted (using creduce) from SV-COMP task list-simple/dll2c_remove_all.i | ||
| #include <stdlib.h> | ||
karoliineh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <goblint.h> | ||
|
|
||
| typedef struct node { | ||
| struct node *next; | ||
| struct node *prev; | ||
| } * DLL; | ||
|
|
||
| void dll_remove(DLL *head) { | ||
| DLL temp = (*head)->next; | ||
| if (temp == *head) { | ||
| __goblint_check(temp == *head); | ||
| __goblint_check(temp != *head); // FAIL | ||
| free(*head); | ||
| } | ||
| else { | ||
| __goblint_check(temp != *head); | ||
| __goblint_check(temp == *head); // FAIL | ||
| (*head)->prev->next = temp; | ||
| free(*head); | ||
| *head = temp; | ||
| } | ||
| } | ||
| main() { | ||
| DLL s = malloc(sizeof(struct node)); | ||
| s->next = s->prev = malloc(sizeof(struct node)); | ||
|
|
||
| dll_remove(&s); | ||
| dll_remove(&s); | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
tests/regression/74-invalid_deref/32-dll2c_append_equal-mini.c
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,17 @@ | ||
| // PARAM: --set ana.activated[+] memOutOfBounds | ||
| // Minimized version of SV-COMP task list-simple/dll2c_append_equal.i | ||
| #include <stdlib.h> | ||
|
|
||
| typedef struct node { | ||
| struct node *next; | ||
| struct node *prev; | ||
| int data; | ||
| } *DLL; | ||
|
|
||
| int main(void) { | ||
| DLL temp = (DLL) malloc(sizeof(struct node)); | ||
| temp->next = NULL; // NOWARN | ||
| temp->prev = NULL; // NOWARN | ||
| temp->data = 1; // NOWARN | ||
| return temp; | ||
| } |
Oops, something went wrong.
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.
Nice catch, I guess this tended to kill us almost all of the time.
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.
There's also a documentation problem (by me) that might've contributed to this:
analyzer/src/cdomain/value/cdomains/offset_intf.ml
Lines 92 to 96 in 153ce28
Contrary to the description, it returns the offset in bits (matching what CIL has). It was fine for
semantic_equalbecause both would be in bits, but not for other uses (this is the only other one I think).I'll have to open a follow-up PR to fix that. Changing the documentation would be easy, but it's not entirely the right thing:
ptrdiff_tis large enough to fit offsets in bytes, but not necessarily in bits (in practice the difference might be irrelevant unless a program actually allocates more than 8th of the address space). Havingto_indexreturn bytes would be consistent withptrdiff_ikind.