Analyzer uses original signedness for tainted offset checks.
Fixes incorrect bounds checking in the analyzer when dealing with tainted offsets.
The GCC analyzer previously mishandled tainted offset checks after certain integer casts. Specifically, when an unsigned type was cast to a wider type of the same bit width, the analyzer lost the original type’s lower bound of zero. This commit restores the original type information, ensuring accurate upper-bounds checking and fixing false positives in various taint-related tests.
In Details
The analyzer's region model in sm-taint.cc now recovers the representative tree's type for offsets involved in same-width casts. Previously, certain casts (e.g., unsigned int to sizetype on ILP32) were not properly undone by the taint checking logic, leading to incorrect bounds analysis. This change ensures the original signedness is considered, resolving issues where the analyzer incorrectly reported "without bounds checking" or warned about already-checked upper bounds.
- analyzer
- A GCC component that statically analyzes code to find potential bugs, such as use-after-free, buffer overflows, and uninitialized values, without executing the code.
- taint checking
- A type of static analysis that tracks the flow of data from untrusted sources (taints) to sensitive operations, warning if untrusted data reaches a point where it could cause a security vulnerability.
- ILP32
- A compilation target where data types are 32 bits, but pointers are also 32 bits. This contrasts with LP64 where pointers are 64 bits.
- sizetype
- An unsigned integer type that is large enough to contain the size of any object. It is typically equivalent to
size_t.