Skip to content

Commit 4ddac85

Browse files
steakhaltstellar
authored andcommitted
[analyzer] Fix a security.cert.env.InvalidPtr crash
Fixes #88181 (cherry picked from commit e096c14)
1 parent c6d63d4 commit 4ddac85

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

clang/docs/ReleaseNotes.rst

+4
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,10 @@ Crash and bug fixes
14741474
- Fix false positive in mutation check when using pointer to member function.
14751475
(`#66204 <https://github.com/llvm/llvm-project/issues/66204>`_)
14761476

1477+
- Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
1478+
matched user-defined ``strerror`` and similar library functions.
1479+
(`#88181 <https://github.com/llvm/llvm-project/issues/88181>`_)
1480+
14771481
Improvements
14781482
^^^^^^^^^^^^
14791483

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)