Skip to content

Fix false positives for std::byte pointer scaling - #22933

Merged
jketema merged 3 commits into
mainfrom
copilot/issue-22929-byte-pointer-scaling
Oct 29, 2026
Merged

jketema merged 3 commits into
mainfrom
copilot/issue-22929-byte-pointer-scaling

Conversation

@jketema

@jketema jketema commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Exclude std::byte* source pointers from cpp/suspicious-pointer-scaling, avoiding false positives for intentional typed indexing into byte buffers.
  • Add coverage for both C-style casts and reinterpret_cast, and document the analysis change.

The exemption matches the standard std::byte enum by qualified name. This is an enum by definition of the spec. std::byte should be treated similar to char, so should exempted here.

Fixes #22929

Reproduce #22929 with int-pointer arithmetic from std::byte storage using C-style casts and reinterpret_cast. Record the current false positives alongside the existing char-pointer coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jketema
jketema force-pushed the copilot/issue-22929-byte-pointer-scaling branch from a77d53e to 73542ac Compare October 29, 2026 11:10
Treat std::byte source pointers like char and void buffers when checking pointer scaling, avoiding false positives for intentional typed indexing. Match only the standard byte enum and update both cast-style tests to expect no alerts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the C++ label Oct 29, 2026
Add a minor analysis note for the reduced false positives in suspicious pointer scaling when indexing std::byte buffers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jketema jketema changed the title Add std::byte pointer scaling regression test Fix false positives for std::byte pointer scaling Oct 29, 2026
@jketema
jketema marked this pull request as ready for review October 29, 2026 11:34
@jketema
jketema requested a review from a team as a code owner October 29, 2026 11:34
Copilot AI auto review requested due to automatic review settings October 29, 2026 11:34

Copilot AI 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.

🟢 Approval recommended

No active review issues are identified, and the narrowly scoped change includes targeted regression coverage for the std::byte pointer-casting cases.

No open issues 🎉

What changed in this PR

Updates cpp/suspicious-pointer-scaling to avoid false positives when intentional typed indexing starts from a std::byte* buffer.

Changes:

  • Exempts source pointers based on the qualified std::byte enum.
  • Adds regression coverage for C-style casts and reinterpret_cast.
  • Documents the analysis improvement in a change note.
File Description
cpp/​ql/​test/​query-tests/​Security/​CWE/​CWE-468/​semmle/​IncorrectPointerScaling/​test.cpp Adds coverage for conversions from std::byte* using both cast forms.
cpp/​ql/​src/​Security/​CWE/​CWE-468/​IncorrectPointerScaling.ql Exempts qualified std::byte source pointers from suspicious pointer-scaling results.
cpp/​ql/​src/​change-notes/​2026-10-29-suspicious-pointer-scaling-byte.md Documents the false-positive reduction.

Review effort: Lite (auto)

@jketema

jketema commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

OpenTTD alerts that have disappeared from DCA indeed used std::byte.

@hvitved hvitved 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.

Looks plausible to me.

@jketema
jketema merged commit 18b48aa into main Oct 29, 2026
22 checks passed
@jketema
jketema deleted the copilot/issue-22929-byte-pointer-scaling branch October 29, 2026 15:19
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.

cpp/suspicious-pointer-scaling flags intentional record indexing from std::byte buffers

3 participants