Skip to content

Commit e1fff81

Browse files
committed
[Test] Gate newer objc_getClass tests on OS version.
The last two tests in the NotPresent test check for fixes that went into 5.3. Testing these against earlier runtimes will fail. Add availability checks so we only test when the fix is present. While we're here, switch the symbolic references test to use indirect references. Direct references are very likely to pass the test even without the fix, as the reference is likely to point to readable memory. Indirect references make this much more likely to crash by then reading and dereferencing a pointer from the memory the relative pointer points to. rdar://159034772
1 parent b444a0b commit e1fff81

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

test/Interpreter/SDK/objc_getClass.swift

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,25 @@ testSuite.test("NotPresent") {
256256
// Swift.Int is not a class type.
257257
expectNil(NSClassFromString("Si"))
258258

259-
// Mangled names with byte sequences that look like symbolic references
260-
// should not be demangled.
261-
expectNil(NSClassFromString("\u{1}badnews"));
262-
expectNil(NSClassFromString("$s\u{1}badnews"));
263-
expectNil(NSClassFromString("_T\u{1}badnews"));
264-
265-
// Correct mangled names with additional text afterwards should not resolve.
266-
expectNil(NSClassFromString("_TtC4main20MangledSwiftSubclass_"))
267-
expectNil(NSClassFromString("_TtC4main22MangledSwiftSuperclassXYZ"))
268-
expectNil(NSClassFromString("_TtC4main19MangledObjCSubclass123"))
269-
expectNil(NSClassFromString("_TtC4main21MangledObjCSuperclasswhee"))
259+
if #available(StdlibDeploymentTarget 5.3, *) {
260+
// Mangled names with byte sequences that look like symbolic references
261+
// should not be demangled. Use indirect references to test. Direct
262+
// references often resolve to readable memory, and then the data there
263+
// often looks like a descriptor with an unknown kind and the lookup code
264+
// then fails gracefully. With an indirect reference, the indirected pointer
265+
// is typically garbage and dereferencing it will crash.
266+
expectNil(NSClassFromString("\u{2}badnews"));
267+
expectNil(NSClassFromString("$s\u{2}badnews"));
268+
expectNil(NSClassFromString("_T\u{2}badnews"));
269+
}
270+
271+
if #available(StdlibDeploymentTarget 5.3, *) {
272+
// Correct mangled names with additional text afterwards should not resolve.
273+
expectNil(NSClassFromString("_TtC4main20MangledSwiftSubclass_"))
274+
expectNil(NSClassFromString("_TtC4main22MangledSwiftSuperclassXYZ"))
275+
expectNil(NSClassFromString("_TtC4main19MangledObjCSubclass123"))
276+
expectNil(NSClassFromString("_TtC4main21MangledObjCSuperclasswhee"))
277+
}
270278
}
271279

272280
runAllTests()

0 commit comments

Comments
 (0)