Skip to content

Commit 182b4f3

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 751eabe commit 182b4f3

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
@@ -1741,8 +1741,8 @@ getObjCClassByMangledName(const char * _Nonnull typeName,
17411741
return nullptr;
17421742
}).getMetadata();
17431743
} else {
1744-
metadata = swift_getTypeByMangledNameInEnvironment(
1745-
typeStr.data(), typeStr.size(), /* no substitutions */ nullptr, nullptr);
1744+
metadata = swift_stdlib_getTypeByMangledNameUntrusted(typeStr.data(),
1745+
typeStr.size());
17461746
}
17471747
if (metadata) {
17481748
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)