We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
We must mitigate all arithmetic wrap-around (overflow and underflow). This requires solving it for each of the three variable types:
The text was updated successfully, but these errors were encountered:
One of the common "wrap" patterns is if (val + offset < val) { ... }. These can be found and replaced by Coccinelle:
if (val + offset < val) { ... }
@found@ unsigned long ULONG; expression OFFSET; @@ { + unsigned long sum; ... ( - ULONG + OFFSET < ULONG + check_add_overflow(ULONG, OFFSET, &sum) ) ... ( - ULONG + OFFSET + sum ) ... }
Sorry, something went wrong.
And to generally locate them:
@wrap_check@ void *PTR; unsigned long ULONG; unsigned int UINT; expression OFFSET; @@ ( ( - PTR + OFFSET < PTR + ULONG_MAX - OFFSET > PTR | - ULONG + OFFSET < ULONG + ULONG_MAX - OFFSET > ULONG | - UINT + OFFSET < UINT + UINT_MAX - OFFSET > UINT ) )
But this conversion results in worse code gen. It may be useful to add a wrapper macro:
#define would_add_overflow(a, b) ({ \ typeof(a) __maybe_overflowed_sum; \ check_add_overflow(a, b, &__maybe_overflowed_sum); \ })
See https://godbolt.org/z/Kc7vsMd9W
No branches or pull requests
We must mitigate all arithmetic wrap-around (overflow and underflow). This requires solving it for each of the three variable types:
The text was updated successfully, but these errors were encountered: