[clang] [Clang] Prevent null pointer dereference in TransformUnaryTransformType() (PR #97912)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 6 14:05:00 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (smanna12)

<details>
<summary>Changes</summary>

This patch adds null check after TransformType call to avoid dereferencing a null pointer when calling getType().

---
Full diff: https://github.com/llvm/llvm-project/pull/97912.diff


1 Files Affected:

- (modified) clang/lib/Sema/TreeTransform.h (+6-2) 


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

``````````

</details>


https://github.com/llvm/llvm-project/pull/97912


More information about the cfe-commits mailing list