Skip to content

Commit 04b21d0

Browse files
authored
Limit the recursion depth when trying to get the mangling for a context descriptor (#35314)
* 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. * Only decrement the recursion limit once for each parent visit
1 parent ffeb1d5 commit 04b21d0

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
@@ -1132,7 +1132,7 @@ class MetadataReader {
11321132
Demangle::NodePointer
11331133
buildContextMangling(ContextDescriptorRef descriptor,
11341134
Demangler &dem) {
1135-
auto demangling = buildContextDescriptorMangling(descriptor, dem);
1135+
auto demangling = buildContextDescriptorMangling(descriptor, dem, 50);
11361136
if (!demangling)
11371137
return nullptr;
11381138

@@ -2105,9 +2105,13 @@ class MetadataReader {
21052105

21062106
Demangle::NodePointer
21072107
buildContextDescriptorMangling(const ParentContextDescriptorRef &descriptor,
2108-
Demangler &dem) {
2108+
Demangler &dem, int recursion_limit) {
2109+
if (recursion_limit <= 0) {
2110+
return nullptr;
2111+
}
2112+
21092113
if (descriptor.isResolved()) {
2110-
return buildContextDescriptorMangling(descriptor.getResolved(), dem);
2114+
return buildContextDescriptorMangling(descriptor.getResolved(), dem, recursion_limit);
21112115
}
21122116

21132117
// Try to demangle the symbol name to figure out what context it would
@@ -2125,7 +2129,11 @@ class MetadataReader {
21252129

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

@@ -2142,7 +2150,7 @@ class MetadataReader {
21422150
Demangle::NodePointer parentDemangling = nullptr;
21432151
if (auto parentDescriptor = *parentDescriptorResult) {
21442152
parentDemangling =
2145-
buildContextDescriptorMangling(parentDescriptor, dem);
2153+
buildContextDescriptorMangling(parentDescriptor, dem, recursion_limit - 1);
21462154
if (!parentDemangling && !demangledParentNode)
21472155
return nullptr;
21482156
}

0 commit comments

Comments
 (0)