@@ -1930,7 +1930,7 @@ swift_stdlib_getTypeByMangledNameUntrusted(const char *typeNameStart,
1930
1930
if (c >= ' \x01 ' && c <= ' \x1F ' )
1931
1931
return nullptr ;
1932
1932
}
1933
-
1933
+
1934
1934
return swift_getTypeByMangledName (MetadataState::Complete, typeName, nullptr ,
1935
1935
{}, {}).getType ().getMetadata ();
1936
1936
}
@@ -2197,6 +2197,23 @@ swift_getOpaqueTypeConformance(const void * const *arguments,
2197
2197
// Return the ObjC class for the given type name.
2198
2198
// This gets installed as a callback from libobjc.
2199
2199
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
+
2200
2217
// FIXME: delete this #if and dlsym once we don't
2201
2218
// need to build with older libobjc headers
2202
2219
#if !OBJC_GETCLASSHOOK_DEFINED
@@ -2232,8 +2249,9 @@ getObjCClassByMangledName(const char * _Nonnull typeName,
2232
2249
[&](const Metadata *type, unsigned index) { return nullptr ; }
2233
2250
).getType ().getMetadata ();
2234
2251
} 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 ());
2237
2255
}
2238
2256
if (metadata) {
2239
2257
auto objcClass =
0 commit comments