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