-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
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
CBMC misbehaves in functions with pointer arithmetic computation #8592
Comments
The |
Thank you for your explanation. However, this code snippet was gotten from an embedded software code and the developers would still expect that the This leads to a question -- to what extent should CBMC follow the standard and meet developer expectations without conflicting with each other? For example, would it be okay if CBMC reports a pointer arithmetic error at |
UB is not just "Not defining behaviour" as in "the definition is omitted and something still reliably happens depending on the compiler", UB occurrences actually correspond to violations of assumptions that the compiler actively uses to reason when compiling the source code to machine code. The compiler may still produce an executable that happens to behave in a nice way, but you should not rely on that at all as a developer. Even a verified compiler like Compcert only guarantees correct compilation under the assumption that the program is UB-free. The C standard also has a notion of implementation-defined behaviour, which you can rely on if you know exactly what platform you're compiling to and all the compiler flags used to build the executable. But since there's a tremendous amount of compiler flags and some non-trivial interactions between them, relying on implementation-defined behaviour is also tricky. |
|
We found some arbitrary behavior when using CBMC to verify a function with pointer arithmetic.
For example, in the code below.
The validation
if (diff + expected_len > bufsize) {
is supposed to ensure that data2 contains up to expected_len bytes of data.However, CBMC still reports an OOB read error in the memcpy line.
Looking at the error trace, we find that the
diff
computed is always arbitrary, regardless of the values of data and data2.We tested this using CBMC v6.3.1
The text was updated successfully, but these errors were encountered: