Repository navigation
Conversation
…ddresses Invalidating a value or computing the addresses reachable from it reads array contents at an unknown index. This is not an access by the program, but the default bounds check warned "May access array out of bounds" and set the InvalidDeref flag, e.g., whenever an unknown or library function deeply writes a struct that contains an array. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This gave me deja vu because #2022 put the whole reachability calculation under speculation, which should suppress these checks/warnings. |
| (* For arrays, we ask to read from an unknown index, this will cause it | ||
| * join all its values. *) | ||
| | Array a -> reachable_from_value ask (ValueDomain.CArrays.get (Queries.to_value_domain_ask ask) a (None, ValueDomain.IndexDomain.top ())) t description | ||
| | Array a -> reachable_from_value ask (ValueDomain.CArrays.get ~checkBounds:false (Queries.to_value_domain_ask ask) a (None, ValueDomain.IndexDomain.top ())) t description |
There was a problem hiding this comment.
This one should be unnecessary, this function is only called from the reachable_from_value below.
There was a problem hiding this comment.
It also wouldn't hurt to be more explicit about it, rather than relying so heavily on global speculation state. But either way is fine by me.
|
Probably the check should be in |
Perhaps we shouldn't abuse |
[Opus 5.5]:
Goblint produces spurious "May access array out of bounds" warnings when a value containing an array is invalidated or traversed for reachable addresses. For example, this happens when an unknown function, or a library function with a deep write, gets a pointer to a struct with an array member. These warnings also set the
InvalidDerefflag, sovalid-deref/valid-memsafetycannot be proven.This was because
ValueDomain.invalidate_valueand base'sreachable_from_valueread the array contents at an unknown index viaCArrays.get, which runs the out-of-bounds check by default. These reads are internal to the analysis and not accesses by the program.We fix this by passing
~checkBounds:falseto these reads, as the conversions between array domains inArrayDomainalready do. Real array accesses by the program are still checked.Tests
New regression test
26-undefined_behavior/16-invalidate-array-no-oob.c. On master it fails with the spurious warning at the call. An actual out-of-bounds write afterwards is still reported.Context
This is needed for an upcoming PR that tracks
stdin/stdout/stderras pointers to actualFILEobjects. Libc'sFILEcontains arrays, so calls likefgets(buf, n, stdin), which deep-write the stream, would otherwise trigger this warning.🤖 Generated with Claude Code