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