Skip to content

C++: Add range analysis to cpp/static-buffer-overflow #5923

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 4 commits into from
May 19, 2021

Conversation

MathiasVP
Copy link
Contributor

(Part of https://github.com/github/codeql-c-analysis-team/issues/191.)

This PR uses range analysis to filter out false positives in 2 out of the 3 kinds of problems identified by cpp/static-buffer-overflow.

It does remove a couple of false positives on our usual list of LGTM projects: https://lgtm.com/query/3164577302384476236/. Hopefully, once this PR is merged, we can see what the next class of low-hanging fruit is after the next LGTM upgrade.

@MathiasVP MathiasVP added the C++ label May 18, 2021
@MathiasVP MathiasVP requested a review from a team as a code owner May 18, 2021 15:58
geoffw0
geoffw0 previously approved these changes May 18, 2021
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@geoffw0
Copy link
Contributor

geoffw0 commented May 18, 2021

There's a PR check failure asking for a change note.

@MathiasVP
Copy link
Contributor Author

There's a PR check failure asking for a change note.

Thanks for the heads up. Fixed in 6103aab.

// result in this case we pick the minimum value obtainable from dataflow and range analysis.
result =
upperBound(statedSizeExpr())
.minimum(any(Expr statedSizeSrc |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using the min aggregate here, rather than int::minimum and any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Fixed in 741eed9.

… min aggregate further down since it's no longer needed.
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, merging...

@geoffw0 geoffw0 merged commit 99833f1 into github:main May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants