[clang] 0162df0 - [Clang] Fix null pointer dereference in VisitUsingEnumDecl (#97910)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 10 08:06:59 PDT 2024
Author: smanna12
Date: 2024-07-10T10:06:54-05:00
New Revision: 0162df03cd51e5207310424f2a83b7670c3c2ade
URL: https://github.com/llvm/llvm-project/commit/0162df03cd51e5207310424f2a83b7670c3c2ade
DIFF: https://github.com/llvm/llvm-project/commit/0162df03cd51e5207310424f2a83b7670c3c2ade.diff
LOG: [Clang] Fix null pointer dereference in VisitUsingEnumDecl (#97910)
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.
Added:
Modified:
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..01432301633ed 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3420,6 +3420,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);
More information about the cfe-commits
mailing list