This is an archive of the discontinued LLVM Phabricator instance.

[Analyzer][StreamChecker] Add check for pointer escape.
ClosedPublic

Authored by balazske on May 28 2020, 2:03 AM.

Details

Summary

After an escaped FILE* stream handle it is not possible to make
reliable checks on it because any function call can have effect
on it.

Diff Detail

Event Timeline

balazske created this revision.May 28 2020, 2:03 AM
Szelethus added inline comments.Jun 4 2020, 3:25 AM
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
439–441

How does this interact with D78280?

952–954

Foreach?

balazske marked 2 inline comments as done.Jun 4 2020, 6:36 AM
balazske added inline comments.
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
439–441

That change needs to be updated after this. A new "escaped" stream state is needed to avoid recognizing an escaped stream again.

952–954

The foreach type loop does work too, will be updated (this code is taken from another checker).

balazske updated this revision to Diff 268459.Jun 4 2020, 6:54 AM

Using range-based for loop.

balazske updated this revision to Diff 268701.Jun 5 2020, 1:27 AM

Removed bad empty line.

Szelethus added a subscriber: NoQ.

@NoQ @baloghadamsoftware Escapes are more within your realm of expertise. Anything to add?

From my end, this looks okay.

clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
439–441

Why not take that approach now? I mean that instead of deleting the stream from the map set its state to "escaped".

NoQ accepted this revision.Jun 14 2020, 3:33 AM

@NoQ @baloghadamsoftware Escapes are more within your realm of expertise. Anything to add?

This looks like a fairly standard approach to take, no objections.

clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
952–954

this code is taken from another checker

We were only allowed to use C++11 in LLVM very recently. Most of our code was written before that happened.

This revision is now accepted and ready to land.Jun 14 2020, 3:33 AM
This revision was automatically updated to reflect the committed changes.