Skip to content

Enhance cpp/overflow-calculated - detect out-of-bounds write caused by passing the buffer size in bytes (using sizeof) instead of the number of elements to wcsftime, allowing the function to overrun the allocated buffer. #19721

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

Closed
wants to merge 1 commit into from

Conversation

felickz
Copy link
Contributor

@felickz felickz commented Jun 10, 2025

This pull request improves the detection of buffer overflow issues in the OverflowCalculated.ql query.

Improvements to buffer overflow detection:

  • Enhanced query description: The description of the query has been updated to include scenarios involving incorrect size calculations for wide character functions, improving clarity and scope. Additionally, the precision level was set to "medium" to better reflect the query's behavior. (cpp/ql/src/Critical/OverflowCalculated.ql, cpp/ql/src/Critical/OverflowCalculated.qlL2-R5)

  • New predicate for wide character size issues: Added the wideCharSizeofProblem predicate to detect cases where the sizeof operator is incorrectly used with wcsftime, leading to potential buffer overflows. The predicate checks for miscalculations in the count parameter by ensuring that the size is expressed in terms of wchar_t elements rather than bytes. (cpp/ql/src/Critical/OverflowCalculated.ql, cpp/ql/src/Critical/OverflowCalculated.qlR44-R64)

  • Updated query logic: Modified the where clause in the query to include the new wideCharSizeofProblem predicate, enabling the detection of both traditional space problems and wide character size issues. (cpp/ql/src/Critical/OverflowCalculated.ql, cpp/ql/src/Critical/OverflowCalculated.qlR44-R64)

@github-actions github-actions bot added the C++ label Jun 10, 2025
@felickz felickz closed this Jun 10, 2025
@felickz felickz deleted the patch-4 branch June 10, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant