[clang] [Clang] Prevent null pointer dereference in DiagnoseDeclAvailability() (PR #97095)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 11:43:13 PDT 2024


https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/97095

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.

>From 2f67313eca49d27c4a20b33215a81d4ad80ba7e3 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Fri, 28 Jun 2024 11:29:52 -0700
Subject: [PATCH] [Clang] Prevent null pointer dereference in
 DiagnoseDeclAvailability()

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.
---
 clang/lib/Sema/SemaAvailability.cpp | 1 +
 1 file changed, 1 insertion(+)

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();



More information about the cfe-commits mailing list