-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[Clang] Fix null pointer dereference in VisitUsingEnumDecl #97910
Conversation
This patch addresses static analyzer concern where TSI could be dereferenced after being assigned a null value from SubstType in clang::TemplateDeclInstantiator::VisitUsingEnumDecl(clang::UsingEnumDecl *). The fix now checks null value of TSI after the call to SubstType and return nullptr to prevent potential null pointer dereferences when calling UsingEnumDecl::Create() and ensures safe execution.
@llvm/pr-subscribers-clang Author: None (smanna12) ChangesThis patch addresses static analyzer concern where TSI could be dereferenced after being assigned a null value from SubstType in clang::TemplateDeclInstantiator::VisitUsingEnumDecl(clang::UsingEnumDecl *). The fix now checks null value of TSI after the call to SubstType and return nullptr to prevent potential null pointer dereferences when calling UsingEnumDecl::Create() and ensures safe execution. Full diff: https://github.com/llvm/llvm-project/pull/97910.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 64f6b01bed229..8d856b807889f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3413,6 +3413,10 @@ Decl *TemplateDeclInstantiator::VisitUsingEnumDecl(UsingEnumDecl *D) {
TypeSourceInfo *TSI = SemaRef.SubstType(D->getEnumType(), TemplateArgs,
D->getLocation(), D->getDeclName());
+
+ if (!TSI)
+ return nullptr;
+
UsingEnumDecl *NewUD =
UsingEnumDecl::Create(SemaRef.Context, Owner, D->getUsingLoc(),
D->getEnumLoc(), D->getLocation(), TSI);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Looks like we’re doing this null check pretty much in every other place SubstType
is used, so this makes sense.
Thank you for the reviews @Sirraide |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/51/builds/1124 Here is the relevant piece of the build log for the reference:
|
This patch addresses static analyzer concern where TSI could be dereferenced after being assigned a null value from SubstType in clang::TemplateDeclInstantiator::VisitUsingEnumDecl(clang::UsingEnumDecl *). The fix now checks null value of TSI after the call to SubstType and return nullptr to prevent potential null pointer dereferences when calling UsingEnumDecl::Create() and ensures safe execution.
This patch addresses static analyzer concern where TSI could be dereferenced after being assigned a null value from SubstType in clang::TemplateDeclInstantiator::VisitUsingEnumDecl(clang::UsingEnumDecl *).
The fix now checks null value of TSI after the call to SubstType and return nullptr to prevent potential null pointer dereferences when calling UsingEnumDecl::Create() and ensures safe execution.