Skip to content

Commit da71f6b

Browse files
committed
[Reflection] Fix length calculation in readTypeRef.
The code was skipping 4/8 bytes to jump overn embedded reference, but it actually needs to skip 5/9 bytes in order to skip over the leading control character as well. Also change the abort() calls to return nullptr so that we can fail more gracefully if this code is ever presented with bad data, since we want inspection tools to be robust in the face of garbage. rdar://problem/56460096
1 parent 6acf8db commit da71f6b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

stdlib/public/Reflection/TypeRefBuilder.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ RemoteRef<char> TypeRefBuilder::readTypeRef(uint64_t remoteAddr) {
4444
}
4545
}
4646
// TODO: Try using MetadataReader to read the string here?
47-
fputs("invalid type ref pointer\n", stderr);
48-
abort();
47+
48+
// Invalid type ref pointer.
49+
return nullptr;
4950

5051
found_type_ref:
5152
// Make sure there's a valid mangled string within the bounds of the
@@ -57,16 +58,16 @@ RemoteRef<char> TypeRefBuilder::readTypeRef(uint64_t remoteAddr) {
5758
goto valid_type_ref;
5859

5960
if (c >= '\1' && c <= '\x17')
60-
i = i.atByteOffset(4);
61+
i = i.atByteOffset(5);
6162
else if (c >= '\x18' && c <= '\x1F') {
62-
i = i.atByteOffset(PointerSize);
63+
i = i.atByteOffset(PointerSize + 1);
6364
} else {
6465
i = i.atByteOffset(1);
6566
}
6667
}
6768

68-
fputs("unterminated type ref\n", stderr);
69-
abort();
69+
// Unterminated string.
70+
return nullptr;
7071

7172
valid_type_ref:
7273
// Look past the $s prefix if the string has one.

0 commit comments

Comments
 (0)