3 ms·
Rust: Detect Unsigned Integer Underflow
- errcorrectcode 5y agoIf it can be assumed that only modern processors are that can deliver 2's-complement modulo (not saturation) results are used, then testing is easy: #define IS_UINT_SUB_UNDERFLOW (x, y) ((x) - (y) > (x)) #define IS_UINT_ADD_OVERFLOW (x, y) ((x) + (y) < (x)) #define IS_UINT_MUL_OVERFLOW (x, y, size_max) ((x) && (y) > (size_max) / (x))
- pornel 5y agoThe vulnerable Linux code was performing a string concatenation. Such operation in Rust would be done with `string.push_str()` or `format!()`. Definitely not with unchecked indexing into a manually-allocated array.