Skip to content

Commit

Permalink
[analyzer] Fix a security.cert.env.InvalidPtr crash
Browse files Browse the repository at this point in the history
  • Loading branch information
steakhal committed Apr 17, 2024
1 parent a6fcbcc commit e096c14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,8 @@ Static Analyzer
but not under any case blocks if ``unroll-loops=true`` analyzer config is
set. (#GH68819)
- Support C++23 static operator calls. (#GH84972)
- Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
matched user-defined ``strerror`` and similar library functions. (GH#88181)

New features
^^^^^^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ void InvalidPtrChecker::postPreviousReturnInvalidatingCall(
CE, LCtx, CE->getType(), C.blockCount());
State = State->BindExpr(CE, LCtx, RetVal);

const auto *SymRegOfRetVal =
dyn_cast_or_null<SymbolicRegion>(RetVal.getAsRegion());
if (!SymRegOfRetVal)
return;

// Remember to this region.
const auto *SymRegOfRetVal = cast<SymbolicRegion>(RetVal.getAsRegion());
const MemRegion *MR = SymRegOfRetVal->getBaseRegion();
State = State->set<PreviousCallResultMap>(FD, MR);

Expand Down
10 changes: 10 additions & 0 deletions clang/test/Analysis/invalid-ptr-checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,security.cert.env.InvalidPtr -verify %s

// expected-no-diagnostics

namespace other {
int strerror(int errnum); // custom strerror
void no_crash_on_custom_strerror() {
(void)strerror(0); // no-crash
}
} // namespace other

0 comments on commit e096c14

Please sign in to comment.