@@ -1919,7 +1919,7 @@ swift_stdlib_getTypeByMangledNameUntrusted(const char *typeNameStart,
1919
1919
if (c >= ' \x01 ' && c <= ' \x1F ' )
1920
1920
return nullptr ;
1921
1921
}
1922
-
1922
+
1923
1923
return swift_getTypeByMangledName (MetadataState::Complete, typeName, nullptr ,
1924
1924
{}, {}).getType ().getMetadata ();
1925
1925
}
@@ -2186,6 +2186,23 @@ swift_getOpaqueTypeConformance(const void * const *arguments,
2186
2186
// Return the ObjC class for the given type name.
2187
2187
// This gets installed as a callback from libobjc.
2188
2188
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
+
2189
2206
// FIXME: delete this #if and dlsym once we don't
2190
2207
// need to build with older libobjc headers
2191
2208
#if !OBJC_GETCLASSHOOK_DEFINED
@@ -2221,8 +2238,9 @@ getObjCClassByMangledName(const char * _Nonnull typeName,
2221
2238
[&](const Metadata *type, unsigned index) { return nullptr ; }
2222
2239
).getType ().getMetadata ();
2223
2240
} 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 ());
2226
2244
}
2227
2245
if (metadata) {
2228
2246
auto objcClass =
0 commit comments