This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix ValistChecker false-positive involving symbolic pointers
ClosedPublic

Authored by steakhal on Apr 22 2022, 1:47 AM.

Details

Summary

In the following example:

int va_list_get_int(va_list *va) {
  return va_arg(*va, int); // FP
}

The *va expression will be something like Element{SymRegion{va}, 0, va_list}.
We use ElementRegions for representing the result of the dereference.
In this case, the IsSymbolic was set to false in the
getVAListAsRegion().

Hence, before checking if the memregion is a SymRegion, we should take
the base of that region.

Analogously to the previous example, one can craft other cases:

struct MyVaList {
  va_list l;
};
int va_list_get_int(struct MyVaList va) {
  return va_arg(va.l, int); // FP
}

But it would also work if the va_list would be in the base or derived
part of a class. ObjCIvarRegions are likely also susceptible.
I'm not explicitly demonstrating these cases.

PS: Check the MemRegion::getBaseRegion() definition.

Fixes #55009

Diff Detail

Event Timeline

steakhal created this revision.Apr 22 2022, 1:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 1:47 AM
steakhal requested review of this revision.Apr 22 2022, 1:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 1:47 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
xazax.hun accepted this revision.Apr 22 2022, 6:21 AM
This revision is now accepted and ready to land.Apr 22 2022, 6:21 AM