This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] ArrayBoundCheckerV2 should listen to check::Bind as well
AbandonedPublic

Authored by steakhal on Aug 29 2023, 8:20 AM.

Details

Summary

Turns out check::Location is not always called when storing a value to a
location. See the details here:
https://discourse.llvm.org/t/checklocation-vs-checkbind-when-isload-false/72728

To catch the remaining cases when binding to a location, subscribe to the
check::Bind callback.

(CWE-122 Heap Based Buffer Overflow: CWE-805-class-loop)

Depends on D159105

Diff Detail

Event Timeline

steakhal created this revision.Aug 29 2023, 8:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2023, 8:20 AM
steakhal requested review of this revision.Aug 29 2023, 8:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2023, 8:20 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
donat.nagy accepted this revision.Aug 30 2023, 2:11 AM

This seems to be a straightforward improvement over the current situation; LGTM if you test(ed) it on some real-life code (to ensure that it doesn't introduce a corner case that crashes).

clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
46

I'd call this function performCheck or something similar, but "impl" is also fine especially if it's a traditional name (that I haven't encountered yet in clang SA code).

This revision is now accepted and ready to land.Aug 30 2023, 2:11 AM
steakhal added inline comments.Aug 30 2023, 2:34 AM
clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
46

Yes, I'll rename it. I was already thinking about it.

steakhal planned changes to this revision.Aug 31 2023, 12:37 AM

This patch would cause FPs on this code:

struct S {};
void zero_size_array() {
  S arr[0];
  (void)arr;
}

Being short on time, I'll just drop this commit from the stack and come back in a late future.
This might be related to D131501.

steakhal abandoned this revision.Aug 31 2023, 2:49 AM