[PATCH] D63789: [ODRHash] Fix null pointer dereference for ObjC selectors with empty slots.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 25 13:38:01 PDT 2019


vsapsai created this revision.
vsapsai added a reviewer: rtrieu.
Herald added subscribers: dexonsmith, jkorous.

Because `Selector::getIdentifierInfoForSlot` returns NULL if a slot has
no corresponding identifier, use `Selector::getNameForSlot` instead.

rdar://problem/51615164


https://reviews.llvm.org/D63789

Files:
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/odr_hash.mm


Index: clang/test/Modules/odr_hash.mm
===================================================================
--- clang/test/Modules/odr_hash.mm
+++ clang/test/Modules/odr_hash.mm
@@ -57,6 +57,10 @@
 @interface Interface3 <T : I1 *>
 @end
 
+ at interface EmptySelectorSlot
+- (void)notify:(int)arg :(int)empty;
+ at end
+
 #endif
 
 #if defined(FIRST)
@@ -289,6 +293,14 @@
 }  // namespace ObjCTypeParam
 }  // namespace Types
 
+namespace rdar51615164 {
+#if defined(FIRST) || defined(SECOND)
+void notify(EmptySelectorSlot *obj) {
+  [obj notify:0 :0];
+}
+#endif
+}  // namespace rdar51615164
+
 // Keep macros contained to one file.
 #ifdef FIRST
 #undef FIRST
Index: clang/lib/AST/ODRHash.cpp
===================================================================
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -72,7 +72,7 @@
     AddBoolean(S.isUnarySelector());
     unsigned NumArgs = S.getNumArgs();
     for (unsigned i = 0; i < NumArgs; ++i) {
-      AddIdentifierInfo(S.getIdentifierInfoForSlot(i));
+      ID.AddString(S.getNameForSlot(i));
     }
     break;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63789.206522.patch
Type: text/x-patch
Size: 1082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190625/7adaaa24/attachment.bin>


More information about the cfe-commits mailing list