-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Add a few more models #20769
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
base: main
Are you sure you want to change the base?
C++: Add a few more models #20769
Conversation
There was a problem hiding this 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 adds taint flow models for character conversion functions (toupper, tolower) and the iconv function, along with support for additional GCC builtin variants of string manipulation functions. The changes improve taint tracking capabilities for these commonly used functions.
- Adds YAML models for
toupper,tolower, andiconvfunctions to enable taint tracking - Includes test cases demonstrating taint flow through these functions
- Extends existing string function models to include GCC builtin
__builtin___*_chkvariants
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cpp/ql/lib/ext/cctype.model.yml | Defines taint flow models for toupper/tolower functions |
| cpp/ql/lib/ext/iconv.model.yml | Defines value flow model for iconv function |
| cpp/ql/test/library-tests/dataflow/taint-tests/taint.cpp | Adds test cases for toupper, tolower, and iconv taint tracking |
| cpp/ql/test/library-tests/dataflow/taint-tests/test_mad-signatures.expected | Auto-generated expected test output |
| cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected | Auto-generated expected test output |
| cpp/ql/lib/semmle/code/cpp/models/implementations/Strcpy.qll | Adds support for GCC builtin strcpy/stpcpy/strncpy/stpncpy variants |
| cpp/ql/lib/semmle/code/cpp/models/implementations/Strcat.qll | Adds support for GCC builtin strcat/strncat variants |
| cpp/ql/lib/semmle/code/cpp/models/implementations/Memset.qll | Adds support for GCC builtin memset variant |
| cpp/ql/lib/semmle/code/cpp/models/implementations/Memcpy.qll | Adds support for GCC builtin memmove variant and updates documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "strlcpy", // strlcpy(dst, src, dst_size) | ||
| "__builtin___strcpy_chk", // __builtin___strcpy_chk (dest, src, magic); | ||
| "__builtin___stpcpy_chk", // __builtin___stpcpy_chk (dest, src, magic); | ||
| "__builtin___stpncpy_chk", // __builtin___stpncpy_chk(dest, src, max_amount, magic) |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment for __builtin___stpncpy_chk is missing a semicolon at the end, unlike the other builtin function comments on lines 40, 41, and 43. Add a semicolon for consistency.
| "__builtin___stpncpy_chk", // __builtin___stpncpy_chk(dest, src, max_amount, magic) | |
| "__builtin___stpncpy_chk", // __builtin___stpncpy_chk(dest, src, max_amount, magic); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we just want to get rid of the semi-colons, similarly for strcat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem to be quite right. Comments below.
| this.getName() = | ||
| [ | ||
| "strncat", "wcsncat", "_mbsncat", "_mbsncat_l", "__builtin___strncat_chk", | ||
| "__builtin___strcat_chk" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what __builtin___strcat_chk (without the n) is doing here. This seems to be from taint flow from the numeric argument of strncat.
| this.getName() | ||
| .matches([ | ||
| "%ncpy%", "%nbcpy%", "%xfrm%", "strlcpy", "__builtin___strcpy_chk", | ||
| "__builtin___stpcpy_chk", "__builtin___stpncpy_chk", "__builtin___strncpy_chk" | ||
| ]) and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that __builtin___stpncpy_chk and __builtin___strncpy_chk are already covered by %ncpy%.
The __builtin___strcpy_chk and __builtin___stpcpy_chk functions don't seem to belong here, as they don't have a size argument.
Just a couple more models that I encountered a need for while doing some Microsoft work