llvm-project
8cb15310 - [scudo] Fix undefined behavior and UBSan integer overflow issues (#238900)

Commit
13 days ago
[scudo] Fix undefined behavior and UBSan integer overflow issues (#238900) - Cast `1` to `uptr` before bit-shifting in `size_class_map.h` to avoid signed 32-bit shift overflows. - Fix inverted pointer subtraction in `primary64.h` (`BatchGroupBase - Region->RegionBeg`), initialize `MinDistance` with `~static_cast<uptr>(1)`, and guard `RegionPushedBytesDelta` against unsigned underflow when `BytesInFreeList` decreases. - Avoid unsigned underflow when `PossibleRegions` entries are `0` in `primary32.h` by comparing against `ClassId + 1U`. - Reset `QuarantinePos` to `0` instead of `-1U` in `secondary.h` so `QuarantinePos + 1` in `store()` does not overflow `u32`. - Annotate intentional unsigned wraparound/modular arithmetic with `__attribute__((no_sanitize("unsigned-integer-overflow")))` in `combined.h` (extracted into `canQuarantine()`), `stack_depot.h`, and `stats.h`. Used Gemini to review changes.
Parents
Loading