-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Reuse bounded predicate in TaintedAllocationSize query #17220
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,4 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* The `cpp/uncontrolled-allocation-size` ("Uncontrolled allocation size") query now considers arithmetic operations that might reduce the size of user input as a barrier. The query therefore produces fewer false positive results. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,6 +180,15 @@ void more_bounded_tests() { | |
} | ||
} | ||
|
||
{ | ||
int size = atoi(getenv("USER")); | ||
|
||
if (size % 100) | ||
{ | ||
malloc(size * sizeof(int)); // GOOD | ||
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. Why is this example "GOOD", but the one from lines 132-136 isn't? 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. I guess my actual question is: how is modulo supposed to bound the input here? 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. That's a good point. It does not 😅. As it stands it's actually an example of a false negative. What I had in my mind was an example like this: int size = atoi(getenv("USER"));
int size2 = size % 100;
malloc(size2 * sizeof(int)); 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. Thanks for pointing this out @intrigus-lgtm. It's fixed now by #17269. |
||
} | ||
} | ||
|
||
{ | ||
int size = atoi(getenv("USER")); | ||
|
||
|
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.
Note that it's a pretty common pattern to have three cases to think about (1) a thing holds (2) the thing doesn't hold and (3) we weren't able to determine either. If we had another predicate,
convertedExprNeverOverflows
, this would not be the inverse ofconvertedExprMightOverflow
(due to case 3) and the choice between usingconvertedExprNeverOverflows
ornot convertedExprMightOverflow
as we do here would be meaningful.