https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/90482

>From 1a46c4d8bd22f8802058a1865a3b18d5aa4f2cd4 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.ma...@intel.com>
Date: Mon, 29 Apr 2024 07:58:44 -0700
Subject: [PATCH 1/2] [Clang] Fix Null Pointer Dereference in
 Sema::BuildClassMessageImplicit()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The issue arises in the assert statement.

The code asserts that either isSuperReceiver && Loc.isValid() is true or 
receiverTypeInfo is not null.

However, the subsequent line (return BuildClassMessage(...)) dereferences 
receiverTypeInfo without explicitly checking if it’s null.

The fix involves ensuring that the receiverTypeInfo pointer is not null before 
dereferencing it.

By adding a null check for receiverTypeInfo, we prevent potential undefined 
behavior due to null pointer dereference.
---
 clang/lib/Sema/SemaExprObjC.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index b13a9d426983b7..bdc16687e86dce 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -2440,10 +2440,12 @@ ExprResult Sema::BuildClassMessageImplicit(QualType 
ReceiverType,
   assert(((isSuperReceiver && Loc.isValid()) || receiverTypeInfo) &&
          "Either the super receiver location needs to be valid or the receiver 
"
          "needs valid type source information");
-  return BuildClassMessage(receiverTypeInfo, ReceiverType,
-                          /*SuperLoc=*/isSuperReceiver ? Loc : 
SourceLocation(),
-                           Sel, Method, Loc, Loc, Loc, Args,
-                           /*isImplicit=*/true);
+  if (receiverTypeInfo) {
+    return BuildClassMessage(receiverTypeInfo, ReceiverType,
+                            /*SuperLoc=*/isSuperReceiver ? Loc : 
SourceLocation(),
+                             Sel, Method, Loc, Loc, Loc, Args,
+                             /*isImplicit=*/true);
+  }
 }
 
 static void applyCocoaAPICheck(Sema &S, const ObjCMessageExpr *Msg,

>From 063df2e40a74a45ced30eb592c401f1ed35b852b Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.ma...@intel.com>
Date: Mon, 29 Apr 2024 08:09:10 -0700
Subject: [PATCH 2/2] Fix clang format errors

---
 clang/lib/Sema/SemaExprObjC.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index bdc16687e86dce..07e927cef34c71 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -2441,10 +2441,11 @@ ExprResult Sema::BuildClassMessageImplicit(QualType 
ReceiverType,
          "Either the super receiver location needs to be valid or the receiver 
"
          "needs valid type source information");
   if (receiverTypeInfo) {
-    return BuildClassMessage(receiverTypeInfo, ReceiverType,
-                            /*SuperLoc=*/isSuperReceiver ? Loc : 
SourceLocation(),
-                             Sel, Method, Loc, Loc, Loc, Args,
-                             /*isImplicit=*/true);
+    return BuildClassMessage(
+        receiverTypeInfo, ReceiverType,
+        /*SuperLoc=*/isSuperReceiver ? Loc : SourceLocation(), Sel, Method, 
Loc,
+        Loc, Loc, Args,
+        /*isImplicit=*/true);
   }
 }
 

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to