Skip to content

Commit e096c14

Browse files
committed
[analyzer] Fix a security.cert.env.InvalidPtr crash
Fixes #88181
1 parent a6fcbcc commit e096c14

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clang/docs/ReleaseNotes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,8 @@ Static Analyzer
679679
but not under any case blocks if ``unroll-loops=true`` analyzer config is
680680
set. (#GH68819)
681681
- Support C++23 static operator calls. (#GH84972)
682+
- Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
683+
matched user-defined ``strerror`` and similar library functions. (GH#88181)
682684

683685
New features
684686
^^^^^^^^^^^^

clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,12 @@ void InvalidPtrChecker::postPreviousReturnInvalidatingCall(
205205
CE, LCtx, CE->getType(), C.blockCount());
206206
State = State->BindExpr(CE, LCtx, RetVal);
207207

208+
const auto *SymRegOfRetVal =
209+
dyn_cast_or_null<SymbolicRegion>(RetVal.getAsRegion());
210+
if (!SymRegOfRetVal)
211+
return;
212+
208213
// Remember to this region.
209-
const auto *SymRegOfRetVal = cast<SymbolicRegion>(RetVal.getAsRegion());
210214
const MemRegion *MR = SymRegOfRetVal->getBaseRegion();
211215
State = State->set<PreviousCallResultMap>(FD, MR);
212216

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,security.cert.env.InvalidPtr -verify %s
2+
3+
// expected-no-diagnostics
4+
5+
namespace other {
6+
int strerror(int errnum); // custom strerror
7+
void no_crash_on_custom_strerror() {
8+
(void)strerror(0); // no-crash
9+
}
10+
} // namespace other

0 commit comments

Comments
 (0)