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
C++: Constant type-bounds in the new range analysis #13783
base: main
Are you sure you want to change the base?
C++: Constant type-bounds in the new range analysis #13783
Conversation
…pper bound (and similarly for lower bounds).
| @@ -936,7 +936,7 @@ void two_bounds_from_one_test(short ss, unsigned short us) { | |||
| range(ss); // -32768 .. 32767 | |||
| } | |||
|
|
|||
| if (ss + 1 < sizeof(int)) { // $ overflow=+ | |||
| if (ss + 1 < sizeof(int)) { // $ overflow=- | |||
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've verified the results and they LGTM. I'm still a bit unsure about whether we should suppress constant bounds arising purely from types such as: void f(unsigned int ui) {
unsigned long long ull = ui;
range(ull); // we infer that `ull <= UINT_MAX` here. Is that what we want?
}In any case, I think we can push this feature to a future PR. I've noted this down in our internal issue. |
|
Why wouldn't we want to deduce that |
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.
Some small comments, just to further my understanding of the code.
cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/SemanticExprSpecific.qll
Show resolved
Hide resolved
cpp/ql/test/library-tests/ir/range-analysis/SimpleRangeAnalysis_tests.cpp
Show resolved
Hide resolved
cpp/ql/test/library-tests/ir/range-analysis/SimpleRangeAnalysis_tests.cpp
Show resolved
Hide resolved
Because it's not a very precise bound, and many users have been confused by false positives caused by such very-large-but-sound bounds obtained from type-information only. For example, this change was made because we wanted to be able to distinguish between precise bounds found by bounds from guards, and less precise bounds from type-information, for a high precision version of the And then there's this beauty from an external contributor who had a similar problem: https://github.com/github/codeql/blob/main/cpp/ql/src/experimental/Security/CWE/CWE-561/FindIncorrectlyUsedSwitch.ql#L21 |
Not as part of this PR, but as each bound comes with a reason, we might want to explore whether we can add a new reason for the type bounds that are introduced here. |
|
The DCA alert changes do not make any kind of sense to me. Any clue what was going on there? |
|
|
Thanks. I would be fine with having this merged, assuming DCA against |
|
Good point. I actually didn't test this against |
|
Uh oh. Since we now infer many many more constant bounds the I think that's another good reason to do what Jeroen said here:
But since this is causing FPs on |
This PR adds type-based bounds in the new range analysis library. This allows us to deduce that fewer things overflow, and thus allows us exclude fewer bounds.
I'll test this by locally rebasing this branch onto #12505 and running DCA on that.