[clang] [Clang] Prevent null pointer dereference in DiagnoseDeclAvailability() (PR #97095)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 28 11:43:43 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (smanna12)
<details>
<summary>Changes</summary>
This patch adds an assertion in the DiagnoseDeclAvailabilit() function to ensure that the expected availability attribute is not null before they are passed to hasMatchingEnvironmentOrNone() to prevent potential null pointer dereferences and improve the robustness of the availability diagnostics process.
---
Full diff: https://github.com/llvm/llvm-project/pull/97095.diff
1 Files Affected:
- (modified) clang/lib/Sema/SemaAvailability.cpp (+1)
``````````diff
diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp
index fed1c68d4d33a..df83bbfb7aac8 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -842,6 +842,7 @@ void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
const AvailabilityAttr *AA =
getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
+ assert(AA != nullptr && "expecting valid availability attribute");
bool EnvironmentMatchesOrNone =
hasMatchingEnvironmentOrNone(SemaRef.getASTContext(), AA);
VersionTuple Introduced = AA->getIntroduced();
``````````
</details>
https://github.com/llvm/llvm-project/pull/97095
More information about the cfe-commits
mailing list