@@ -1919,7 +1919,7 @@ swift_stdlib_getTypeByMangledNameUntrusted(const char *typeNameStart,
19191919 if (c >= ' \x01 ' && c <= ' \x1F ' )
19201920 return nullptr ;
19211921 }
1922-
1922+
19231923 return swift_getTypeByMangledName (MetadataState::Complete, typeName, nullptr ,
19241924 {}, {}).getType ().getMetadata ();
19251925}
@@ -2186,6 +2186,23 @@ swift_getOpaqueTypeConformance(const void * const *arguments,
21862186// Return the ObjC class for the given type name.
21872187// This gets installed as a callback from libobjc.
21882188
2189+ static bool validateObjCMangledName (const char *_Nonnull typeName) {
2190+ // Accept names with a mangling prefix.
2191+ if (getManglingPrefixLength (typeName))
2192+ return true ;
2193+
2194+ // Accept names that start with a digit (unprefixed mangled names).
2195+ if (isdigit (typeName[0 ]))
2196+ return true ;
2197+
2198+ // Accept names that contain a dot.
2199+ if (strchr (typeName, ' .' ))
2200+ return true ;
2201+
2202+ // Reject anything else.
2203+ return false ;
2204+ }
2205+
21892206// FIXME: delete this #if and dlsym once we don't
21902207// need to build with older libobjc headers
21912208#if !OBJC_GETCLASSHOOK_DEFINED
@@ -2221,8 +2238,9 @@ getObjCClassByMangledName(const char * _Nonnull typeName,
22212238 [&](const Metadata *type, unsigned index) { return nullptr ; }
22222239 ).getType ().getMetadata ();
22232240 } else {
2224- metadata = swift_stdlib_getTypeByMangledNameUntrusted (typeStr.data (),
2225- typeStr.size ());
2241+ if (validateObjCMangledName (typeName))
2242+ metadata = swift_stdlib_getTypeByMangledNameUntrusted (typeStr.data (),
2243+ typeStr.size ());
22262244 }
22272245 if (metadata) {
22282246 auto objcClass =
0 commit comments