@@ -1930,7 +1930,7 @@ swift_stdlib_getTypeByMangledNameUntrusted(const char *typeNameStart,
19301930 if (c >= ' \x01 ' && c <= ' \x1F ' )
19311931 return nullptr ;
19321932 }
1933-
1933+
19341934 return swift_getTypeByMangledName (MetadataState::Complete, typeName, nullptr ,
19351935 {}, {}).getType ().getMetadata ();
19361936}
@@ -2197,6 +2197,23 @@ swift_getOpaqueTypeConformance(const void * const *arguments,
21972197// Return the ObjC class for the given type name.
21982198// This gets installed as a callback from libobjc.
21992199
2200+ static bool validateObjCMangledName (const char *_Nonnull typeName) {
2201+ // Accept names with a mangling prefix.
2202+ if (getManglingPrefixLength (typeName))
2203+ return true ;
2204+
2205+ // Accept names that start with a digit (unprefixed mangled names).
2206+ if (isdigit (typeName[0 ]))
2207+ return true ;
2208+
2209+ // Accept names that contain a dot.
2210+ if (strchr (typeName, ' .' ))
2211+ return true ;
2212+
2213+ // Reject anything else.
2214+ return false ;
2215+ }
2216+
22002217// FIXME: delete this #if and dlsym once we don't
22012218// need to build with older libobjc headers
22022219#if !OBJC_GETCLASSHOOK_DEFINED
@@ -2232,8 +2249,9 @@ getObjCClassByMangledName(const char * _Nonnull typeName,
22322249 [&](const Metadata *type, unsigned index) { return nullptr ; }
22332250 ).getType ().getMetadata ();
22342251 } else {
2235- metadata = swift_stdlib_getTypeByMangledNameUntrusted (typeStr.data (),
2236- typeStr.size ());
2252+ if (validateObjCMangledName (typeName))
2253+ metadata = swift_stdlib_getTypeByMangledNameUntrusted (typeStr.data (),
2254+ typeStr.size ());
22372255 }
22382256 if (metadata) {
22392257 auto objcClass =
0 commit comments