getsentry / sentry-native

Sentry SDK for C, C++ and native applications.
MIT License
404 stars 170 forks source link

fix: remove a potential overflow before conversion #1062

Closed supervacuus closed 1 month ago

supervacuus commented 1 month ago

This is in response to CodeQL security scan alerts 1-3.

Elf[32|64]_Ehdr[.e_phnum|.e_phentsize|.e_shnum|.e_shentsize] are all uint16_t. This means the loop-var i is bounded by uint16_t and should fit in a uint32_t (to prevent unsigned overflow in the loop). A switch to unsigned still makes sense because we reduce the future chance of unnecessary signed overflow (=UB) in the loop body.

All program/section-header table entry sizes are cast to uin64_t even though the multiplication is bound to uint32_t by both factors bound by uint16_t. This fixes the potential overflow before conversion to the bigger type.

skip-changelog

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 82.68%. Comparing base (66e5aae) to head (f3ef6ed). Report is 2 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1062 +/- ## ========================================== + Coverage 82.62% 82.68% +0.06% ========================================== Files 53 53 Lines 7656 7660 +4 Branches 1208 1208 ========================================== + Hits 6326 6334 +8 + Misses 1216 1213 -3 + Partials 114 113 -1 ```