Skip to content

C++: Fix an issue with cpp/suspicious-add-sizeof in BMN databases - #21514

Merged
geoffw0 merged 4 commits into
github:mainfrom
geoffw0:suspicioussizeof
Mar 20, 2026
Merged

C++: Fix an issue with cpp/suspicious-add-sizeof in BMN databases#21514
geoffw0 merged 4 commits into
github:mainfrom
geoffw0:suspicioussizeof

Conversation

@geoffw0

Copy link
Copy Markdown
Contributor

Fix an issue with the cpp/suspicious-add-sizeof query in BMN databases. It's possible to have pointer arithmetic on a pointer to char (or uint8_t) type extracted as pointer arithmetic on a pointer to error type. To avoid spurious results we should assume that this could be a char type and permit arithmetic with sizeof.

@geoffw0
geoffw0 requested a review from a team as a code ownerMarch 19, 2026 13:46
CopilotAI review requested due to automatic review settings March 19, 2026 13:46
@geoffw0geoffw0 added the C++ label Mar 19, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the cpp/suspicious-add-sizeof query to avoid spurious alerts in build-mode: none (BMN) databases when pointer base types are extracted as erroneous, and adds regression coverage plus a change note.

Changes:

  • Treat ErroneousType pointer bases as “char/void-sized” for the purposes of suppressing suspicious + sizeof(...) pointer arithmetic results.
  • Add a buildless test case that exercises extraction-with-errors scenarios and updates expected results accordingly.
  • Add a C++ pack change note documenting the analysis behavior change for BMN databases.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
cpp/ql/src/Security/CWE/CWE-468/SuspiciousAddWithSizeof.qlExpands the query’s “char/void pointer” exemption to include erroneous base types.
cpp/ql/test/query-tests/Security/CWE/CWE-468/semmle/SuspiciousAddWithSizeof/buildless.cppNew buildless test TU (expects extractor errors) to cover erroneous-type pointer arithmetic cases.
cpp/ql/test/query-tests/Security/CWE/CWE-468/semmle/SuspiciousAddWithSizeof/test.cppAdds typedefs/prototype to support the buildless test scenario.
cpp/ql/test/query-tests/Security/CWE/CWE-468/semmle/SuspiciousAddWithSizeof/SuspiciousAddWithSizeof.expectedUpdates expected results to include findings from the new buildless test file.
cpp/ql/src/change-notes/2026-03-19-suspicious-add-sizeof.mdRecords the BMN false-positive fix as a minor analysis change.

You can also share your feedback on Copilot code review. Take the survey.

@jketemajketema left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM if both "regular" and BMN DCA are happy.

@hannahwidnersson-tech

This comment was marked as spam.

@geoffw0
geoffw0 merged commit 208ae7a into github:mainMar 20, 2026
22 checks passed
@geoffw0
geoffw0 deleted the suspicioussizeof branch April 15, 2026 12:01
Sign up for freeto 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.

4 participants

@geoffw0@hannahwidnersson-tech@jketema