Skip to content

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

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
Jul 1, 2024

Conversation

smanna12
Copy link
Contributor

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.

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.
@smanna12 smanna12 requested review from tahonermann and hekota June 28, 2024 18:43
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 28, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 28, 2024

@llvm/pr-subscribers-clang

Author: None (smanna12)

Changes

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

@hekota
Copy link
Member

hekota commented Jul 1, 2024

Thanks!

@smanna12
Copy link
Contributor Author

smanna12 commented Jul 1, 2024

Thank you @hekota for the reviews!

@smanna12 smanna12 merged commit 1c0e722 into llvm:main Jul 1, 2024
8 checks passed
@smanna12 smanna12 deleted the AttrNull branch July 1, 2024 18:04
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
llvm#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.
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
llvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants