-
Notifications
You must be signed in to change notification settings - Fork 88
Fix memOutOfBounds handling of negative pointer offsets
#2017
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
321fe15
f57838e
8ad5fb3
5447075
8400643
08f01ee
9c3cf67
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,14 @@ | ||
| // PARAM: --set ana.activated[+] memOutOfBounds --enable ana.int.interval | ||
| #include <stdlib.h> | ||
|
|
||
| int main() { | ||
| int *b = malloc(2 * sizeof(int)); | ||
| int x; | ||
|
|
||
| *b++ = 0; //NOWARN | ||
|
|
||
| x = *(b - 2); //WARN | ||
|
|
||
| free(b - 1); | ||
| return x; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // PARAM: --set ana.activated[+] memOutOfBounds --enable ana.int.interval | ||
| #include <stdlib.h> | ||
|
|
||
| int main() { | ||
| int *b = malloc(2 * sizeof(int)); | ||
|
|
||
| *b++ = 0; //NOWARN | ||
|
|
||
| if (b[-2]) //WARN | ||
| return 1; | ||
|
|
||
| free(b - 1); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,12 @@ | ||||||||
| // PARAM: --set ana.activated[+] memOutOfBounds --enable ana.int.interval | ||||||||
| #include <stdlib.h> | ||||||||
| #include <stdio.h> | ||||||||
|
|
||||||||
| int main(void) { | ||||||||
| char *buf = malloc(4); | ||||||||
| char *end; | ||||||||
| end = buf + 4; //NOWARN | ||||||||
| printf("%p", (void *) end); //NOWARN | ||||||||
|
Member
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.
Suggested change
So we also see that we do indeed warn if this pointer is dereferenced.
Member
Author
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. ha! it seems you just uncovered an unrelated unsoundness with this ;) I suggest we merge this as is and I will add this suggestion on another PR with an appropriate fix.
Member
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. Yeah, sounds good! |
||||||||
| free(buf); | ||||||||
| return 0; | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // PARAM: --set ana.activated[+] memOutOfBounds --enable ana.int.interval | ||
| #include <stdlib.h> | ||
|
|
||
| struct S { | ||
| unsigned char a; | ||
| unsigned char b:2; | ||
| unsigned char c:2; | ||
| unsigned char d; | ||
| } __attribute__((packed)); | ||
|
|
||
| int main(void) { | ||
| struct S *p = malloc(2); | ||
| p->d = 1; //WARN | ||
| free(p); | ||
| return 0; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.