Skip to content

Commit 3a65d65

Browse files
authored
---
yaml --- r: 343534 b: refs/heads/master-rebranch c: 99d8042 h: refs/heads/master
1 parent aa4d11f commit 3a65d65

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 7a51cfcb8734deda7ae8d59296dc57fcfcec1ee5
1458+
refs/heads/master-rebranch: 99d8042a701a24e4aa21346ac31fb84829767944
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/stdlib/toolchain/Compatibility50/Overrides.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,56 @@ __attribute__((used, section("__DATA,__swift_hooks"))) = {
3636
__attribute__((weak, visibility("hidden")))
3737
extern "C"
3838
char _swift_FORCE_LOAD_$_swiftCompatibility50 = 0;
39+
40+
// Put a getClass hook in front of the system Swift runtime's hook to prevent it
41+
// from trying to interpret symbolic references. rdar://problem/55036306
42+
43+
// FIXME: delete this #if and dlsym once we don't
44+
// need to build with older libobjc headers
45+
#if !OBJC_GETCLASSHOOK_DEFINED
46+
using objc_hook_getClass = BOOL(*)(const char * _Nonnull name,
47+
Class _Nullable * _Nonnull outClass);
48+
#endif
49+
static objc_hook_getClass OldGetClassHook;
50+
51+
static BOOL
52+
getObjCClassByMangledName_untrusted(const char * _Nonnull typeName,
53+
Class _Nullable * _Nonnull outClass) {
54+
// Scan the string for byte sequences that might be recognized as
55+
// symbolic references, and reject them.
56+
for (const char *c = typeName; *c != 0; ++c) {
57+
if (*c < 0x20) {
58+
*outClass = Nil;
59+
return NO;
60+
}
61+
}
62+
63+
if (OldGetClassHook) {
64+
return OldGetClassHook(typeName, outClass);
65+
}
66+
// In case the OS runtime for some reason didn't install a hook, fallback to
67+
// NO.
68+
return NO;
69+
}
70+
71+
__attribute__((constructor))
72+
static void installGetClassHook_untrusted() {
73+
// FIXME: delete this #if and dlsym once we don't
74+
// need to build with older libobjc headers
75+
#if !OBJC_GETCLASSHOOK_DEFINED
76+
using objc_hook_getClass = BOOL(*)(const char * _Nonnull name,
77+
Class _Nullable * _Nonnull outClass);
78+
auto objc_setHook_getClass =
79+
(void(*)(objc_hook_getClass _Nonnull,
80+
objc_hook_getClass _Nullable * _Nonnull))
81+
dlsym(RTLD_DEFAULT, "objc_setHook_getClass");
82+
#endif
83+
84+
#pragma clang diagnostic push
85+
#pragma clang diagnostic ignored "-Wunguarded-availability"
86+
if (objc_setHook_getClass) {
87+
objc_setHook_getClass(getObjCClassByMangledName_untrusted,
88+
&OldGetClassHook);
89+
}
90+
#pragma clang diagnostic pop
91+
}

0 commit comments

Comments
 (0)