Skip to content

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

Open
geoffw0 wants to merge 4 commits intogithub:mainfrom
geoffw0:suspicioussizeof
Open

C++: Fix an issue with cpp/suspicious-add-sizeof in BMN databases#21514
geoffw0 wants to merge 4 commits intogithub:mainfrom
geoffw0:suspicioussizeof

Conversation

@geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Mar 19, 2026

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 owner March 19, 2026 13:46
Copilot AI review requested due to automatic review settings March 19, 2026 13:46
@geoffw0 geoffw0 added the C++ label Mar 19, 2026
Copy link
Contributor

Copilot AI left a comment

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
File Description
cpp/ql/src/Security/CWE/CWE-468/SuspiciousAddWithSizeof.ql Expands the query’s “char/void pointer” exemption to include erroneous base types.
cpp/ql/test/query-tests/Security/CWE/CWE-468/semmle/SuspiciousAddWithSizeof/buildless.cpp New 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.cpp Adds typedefs/prototype to support the buildless test scenario.
cpp/ql/test/query-tests/Security/CWE/CWE-468/semmle/SuspiciousAddWithSizeof/SuspiciousAddWithSizeof.expected Updates expected results to include findings from the new buildless test file.
cpp/ql/src/change-notes/2026-03-19-suspicious-add-sizeof.md Records the BMN false-positive fix as a minor analysis change.

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

Copy link
Contributor

@jketema jketema left a comment

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.

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.

4 participants