Skip to content

Commit a49e0d5

Browse files
committed
Runtime: Hook the ObjC runtime with an untrusted demangler.
We don't want objc_getClass and NSClassFromString to be able to feed arbitrary symbolic reference pointers into the Swift runtime. Fixes rdar://problem/54724618.
1 parent e5e48cb commit a49e0d5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,8 @@ getObjCClassByMangledName(const char * _Nonnull typeName,
17691769
return nullptr;
17701770
}).getMetadata();
17711771
} else {
1772-
metadata = swift_getTypeByMangledNameInEnvironment(
1773-
typeStr.data(), typeStr.size(), /* no substitutions */ nullptr, nullptr);
1772+
metadata = swift_stdlib_getTypeByMangledNameUntrusted(typeStr.data(),
1773+
typeStr.size());
17741774
}
17751775
if (metadata) {
17761776
auto objcClass =

test/Interpreter/SDK/objc_getClass.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ testSuite.test("NotPresent") {
248248

249249
// Swift.Int is not a class type.
250250
expectNil(NSClassFromString("Si"))
251+
252+
// Mangled names with byte sequences that look like symbolic references
253+
// should not be demangled.
254+
expectNil(NSClassFromString("\u{1}badnews"));
255+
expectNil(NSClassFromString("$s\u{1}badnews"));
256+
expectNil(NSClassFromString("_T\u{1}badnews"));
251257
}
252258

253259
runAllTests()

0 commit comments

Comments
 (0)