[clang] [Clang] Prevent null pointer dereference in TransformUnaryTransformType() (PR #97912)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 6 14:24:50 PDT 2024
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/97912
>From c30e531027828d7b531d3791c48779b465e69360 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Sat, 6 Jul 2024 14:02:16 -0700
Subject: [PATCH 1/2] [Clang] Prevent null pointer dereference in
TransformUnaryTransformType
This patch adds null check after TransformType call to avoid dereferencing a null pointer when calling getType().
---
clang/lib/Sema/TreeTransform.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 4450ebaf615cd..eb60528509fc5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6734,8 +6734,12 @@ QualType TreeTransform<Derived>::TransformUnaryTransformType(
QualType Result = TL.getType();
if (Result->isDependentType()) {
const UnaryTransformType *T = TL.getTypePtr();
- QualType NewBase =
- getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
+
+ QualType NewBaseType = getDerived().TransformType(TL.getUnderlyingTInfo());
+ if (!NewBaseType)
+ return QualType();
+ QualType NewBase = NewBaseType->getType();
+
Result = getDerived().RebuildUnaryTransformType(NewBase,
T->getUTTKind(),
TL.getKWLoc());
>From 87eceedcfabb4f3f3b7c69f970716a40c745bf7a Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Sat, 6 Jul 2024 14:24:19 -0700
Subject: [PATCH 2/2] Fix Build errors
---
clang/lib/Sema/TreeTransform.h | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index eb60528509fc5..46ac5ff989e37 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6735,10 +6735,11 @@ QualType TreeTransform<Derived>::TransformUnaryTransformType(
if (Result->isDependentType()) {
const UnaryTransformType *T = TL.getTypePtr();
- QualType NewBaseType = getDerived().TransformType(TL.getUnderlyingTInfo());
- if (!NewBaseType)
+ TypeSourceInfo *NewBaseTSI =
+ getDerived().TransformType(TL.getUnderlyingTInfo());
+ if (!NewBaseTSI)
return QualType();
- QualType NewBase = NewBaseType->getType();
+ QualType NewBaseTSI = NewBaseType->getType();
Result = getDerived().RebuildUnaryTransformType(NewBase,
T->getUTTKind(),
More information about the cfe-commits
mailing list