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

…it()

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.

>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] [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,

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

Reply via email to