Skip to content

Commit b4829c3

Browse files
committed
Limit the recursion depth when trying to get the mangling for a context descriptor
This should help guard against corrupted data in the target app when debugging.
1 parent 4bc7a63 commit b4829c3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

include/swift/Remote/MetadataReader.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ class MetadataReader {
11311131
Demangle::NodePointer
11321132
buildContextMangling(ContextDescriptorRef descriptor,
11331133
Demangler &dem) {
1134-
auto demangling = buildContextDescriptorMangling(descriptor, dem);
1134+
auto demangling = buildContextDescriptorMangling(descriptor, dem, 50);
11351135
if (!demangling)
11361136
return nullptr;
11371137

@@ -2104,9 +2104,13 @@ class MetadataReader {
21042104

21052105
Demangle::NodePointer
21062106
buildContextDescriptorMangling(const ParentContextDescriptorRef &descriptor,
2107-
Demangler &dem) {
2107+
Demangler &dem, int recursion_limit) {
2108+
if (recursion_limit <= 0) {
2109+
return nullptr;
2110+
}
2111+
21082112
if (descriptor.isResolved()) {
2109-
return buildContextDescriptorMangling(descriptor.getResolved(), dem);
2113+
return buildContextDescriptorMangling(descriptor.getResolved(), dem, recursion_limit - 1);
21102114
}
21112115

21122116
// Try to demangle the symbol name to figure out what context it would
@@ -2124,7 +2128,11 @@ class MetadataReader {
21242128

21252129
Demangle::NodePointer
21262130
buildContextDescriptorMangling(ContextDescriptorRef descriptor,
2127-
Demangler &dem) {
2131+
Demangler &dem, int recursion_limit) {
2132+
if (recursion_limit <= 0) {
2133+
return nullptr;
2134+
}
2135+
21282136
// Read the parent descriptor.
21292137
auto parentDescriptorResult = readParentContextDescriptor(descriptor);
21302138

@@ -2141,7 +2149,7 @@ class MetadataReader {
21412149
Demangle::NodePointer parentDemangling = nullptr;
21422150
if (auto parentDescriptor = *parentDescriptorResult) {
21432151
parentDemangling =
2144-
buildContextDescriptorMangling(parentDescriptor, dem);
2152+
buildContextDescriptorMangling(parentDescriptor, dem, recursion_limit - 1);
21452153
if (!parentDemangling && !demangledParentNode)
21462154
return nullptr;
21472155
}

0 commit comments

Comments
 (0)