Skip to content

Backport fix for crash reported in #88181 #89022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,10 @@ Crash and bug fixes
- Fix false positive in mutation check when using pointer to member function.
(`#66204 <https://github.com/llvm/llvm-project/issues/66204>`_)

- Fixed a crash in ``security.cert.env.InvalidPtr`` checker when accidentally
matched user-defined ``strerror`` and similar library functions.
(`#88181 <https://github.com/llvm/llvm-project/issues/88181>`_)

Improvements
^^^^^^^^^^^^

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
Loading