-
Notifications
You must be signed in to change notification settings - Fork 273
Confusing results with --pointer-overflow-check #5426
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
Comments
Thanks for reporting this. At the moment cbmc only reports an overflow when the result of pointer arithmetic cannot be represented with the pointer bit width (e.g., assuming 32-bit pointers, when adding 0xFFFFFFFF to a pointer of value 0xFF000000). There are plans however to change the semantics of |
Oh, I did not know that there was an open discussion about that topic. |
At a bare minimum, we should report an overflow when performing pointer arithmetic that would result in an overflow on the underlying integer representation. As future work, we may want to expand on those checks by reporting overflows when exceeding object bounds, as discussed in diffblue#5426. Fixes: diffblue#5284
At a bare minimum, we should report an overflow when performing pointer arithmetic that would result in an overflow on the underlying integer representation. As future work, we may want to expand on those checks by reporting overflows when exceeding object bounds, as discussed in diffblue#5426. Fixes: diffblue#5284
Arithmetic over pointers requires that they point to valid objects (or one past the end of an object). The test uncovered two further problems: 1) there was a typo in subtraction handling in bv_pointerst; 2) redundant assertions are removed, even when they refer to different expressions. Fixes: diffblue#5426
Arithmetic over pointers requires that they point to valid objects (or one past the end of an object). The test uncovered two further problems: 1) there was a typo in subtraction handling in bv_pointerst; 2) redundant assertions are removed, even when they refer to different expressions. Fixes: diffblue#5426
Arithmetic over pointers requires that they point to valid objects (or one past the end of an object). The test uncovered two further problems: 1) there was a typo in subtraction handling in bv_pointerst; 2) redundant assertions are removed, even when they refer to different expressions. Fixes: diffblue#5426
CBMC version: release 5.12
Operating system: x86_64-linux (Ubuntu 18.04.4)
Exact command line resulting in the issue:
cbmc test.c --pointer-overflow-check
What behaviour did you expect: VERIFICATION FAILED
What happened instead: VERIFICATION SUCCESSFUL
test.c
:Greetings,
I am confused that CBMC reports no errors on the code above: The C standard specifies that incrementing a pointer to an array
further away than the
sizeof(array)+1
is undefined behavior [1].The value of the pointer
p
returned bymalloc
could very well beMAX_POINTER_ADDRESS - 7 * sizeof(int)
, so adding 10 to that value should trigger a pointer overflow error.Am I making a mistake here, or is the tool not doing what I am expecting?
[1] ISO/IEC 9899:1999 - Programming languages — C - ISO - §6.5.6 Additive operators [expr.add] para. 8, accessed 19.07.2020 at http://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf
Exact citation:
When an expression that has integer type is added to or subtracted from a pointer, the result has the type of the pointer operand. If the pointer operand points to an element of an array object, and the array is large enough, the result points to an element offset from the original element such that the difference of the subscripts of the resulting and original array elements equals the integer expression. In other words, if the expression P points to the i-th element of an array object, the expressions (P)+N (equivalently, N+(P)) and (P)-N (where N has the value n) point to, respectively, the i+n-th and i−n-th elements of
the array object, provided they exist. Moreover, if the expression P points to the last element of an array object, the expression (P)+1 points one past the last element of the array object, and if the expression Q points one past the last element of an array object, the expression (Q)-1 points to the last element of the array object. If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined. If the result points one past the last element of the array object, it shall not be used as the operand of a unary * operator that is evaluated.
Edit: changed citation to C99 standard
The text was updated successfully, but these errors were encountered: