|
|
5be97c |
--- binutils.orig/libiberty/rust-demangle.c 2021-05-07 17:13:43.762229783 +0100
|
|
|
5be97c |
+++ binutils-2.36.1/libiberty/rust-demangle.c 2021-05-07 17:14:39.805820593 +0100
|
|
|
5be97c |
@@ -74,6 +74,12 @@ struct rust_demangler
|
|
|
5be97c |
/* Rust mangling version, with legacy mangling being -1. */
|
|
|
5be97c |
int version;
|
|
|
5be97c |
|
|
|
5be97c |
+ /* Recursion depth. */
|
|
|
5be97c |
+ uint recursion;
|
|
|
5be97c |
+ /* Maximum number of times demangle_path may be called recursively. */
|
|
|
5be97c |
+#define RUST_MAX_RECURSION_COUNT 1024
|
|
|
5be97c |
+#define RUST_NO_RECURSION_LIMIT ((uint) -1)
|
|
|
5be97c |
+
|
|
|
5be97c |
uint64_t bound_lifetime_depth;
|
|
|
5be97c |
};
|
|
|
5be97c |
|
|
|
5be97c |
@@ -671,6 +677,15 @@ demangle_path (struct rust_demangler *rd
|
|
|
5be97c |
if (rdm->errored)
|
|
|
5be97c |
return;
|
|
|
5be97c |
|
|
|
5be97c |
+ if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
|
|
|
5be97c |
+ {
|
|
|
5be97c |
+ ++ rdm->recursion;
|
|
|
5be97c |
+ if (rdm->recursion > RUST_MAX_RECURSION_COUNT)
|
|
|
5be97c |
+ /* FIXME: There ought to be a way to report
|
|
|
5be97c |
+ that the recursion limit has been reached. */
|
|
|
5be97c |
+ goto fail_return;
|
|
|
5be97c |
+ }
|
|
|
5be97c |
+
|
|
|
5be97c |
switch (tag = next (rdm))
|
|
|
5be97c |
{
|
|
|
5be97c |
case 'C':
|
|
|
5be97c |
@@ -688,10 +703,7 @@ demangle_path (struct rust_demangler *rd
|
|
|
5be97c |
case 'N':
|
|
|
5be97c |
ns = next (rdm);
|
|
|
5be97c |
if (!ISLOWER (ns) && !ISUPPER (ns))
|
|
|
5be97c |
- {
|
|
|
5be97c |
- rdm->errored = 1;
|
|
|
5be97c |
- return;
|
|
|
5be97c |
- }
|
|
|
5be97c |
+ goto fail_return;
|
|
|
5be97c |
|
|
|
5be97c |
demangle_path (rdm, in_value);
|
|
|
5be97c |
|
|
|
5be97c |
@@ -776,9 +788,15 @@ demangle_path (struct rust_demangler *rd
|
|
|
5be97c |
}
|
|
|
5be97c |
break;
|
|
|
5be97c |
default:
|
|
|
5be97c |
- rdm->errored = 1;
|
|
|
5be97c |
- return;
|
|
|
5be97c |
+ goto fail_return;
|
|
|
5be97c |
}
|
|
|
5be97c |
+ goto pass_return;
|
|
|
5be97c |
+
|
|
|
5be97c |
+ fail_return:
|
|
|
5be97c |
+ rdm->errored = 1;
|
|
|
5be97c |
+ pass_return:
|
|
|
5be97c |
+ if (rdm->recursion != RUST_NO_RECURSION_LIMIT)
|
|
|
5be97c |
+ -- rdm->recursion;
|
|
|
5be97c |
}
|
|
|
5be97c |
|
|
|
5be97c |
static void
|
|
|
5be97c |
@@ -1317,6 +1335,7 @@ rust_demangle_callback (const char *mang
|
|
|
5be97c |
rdm.skipping_printing = 0;
|
|
|
5be97c |
rdm.verbose = (options & DMGL_VERBOSE) != 0;
|
|
|
5be97c |
rdm.version = 0;
|
|
|
5be97c |
+ rdm.recursion = (options & DMGL_NO_RECURSE_LIMIT) ? RUST_NO_RECURSION_LIMIT : 0;
|
|
|
5be97c |
rdm.bound_lifetime_depth = 0;
|
|
|
5be97c |
|
|
|
5be97c |
/* Rust symbols always start with _R (v0) or _ZN (legacy). */
|