Skip to content

Commit 5354f9f

Browse files
authored
Merge pull request swiftlang#26911 from jckarter/objc_getClass-untrusted-demangler
Runtime: Hook the ObjC runtime with an untrusted demangler.
2 parents 03bd71c + a49e0d5 commit 5354f9f

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)