diff options
author | Nick Clifton <nickc@redhat.com> | 2022-07-04 11:05:03 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2022-07-04 11:05:03 +0100 |
commit | 1a770b01ef415e114164b6151d1e55acdee09371 (patch) | |
tree | e3f2e720ecfcc7b2fa2bf4ad7b52754b4a675772 /libiberty | |
parent | 4e82205b68024f5c1a9006fe2b62e1a0fa7f1245 (diff) | |
download | gcc-1a770b01ef415e114164b6151d1e55acdee09371.zip gcc-1a770b01ef415e114164b6151d1e55acdee09371.tar.gz gcc-1a770b01ef415e114164b6151d1e55acdee09371.tar.bz2 |
Prevent another potential stack overflow issue when demangling a maliciouslt mangled Rust name.
libiberty/
* rust-demangle.c (demangle_path_maybe_open_generics): Add
recursion limit.
Diffstat (limited to 'libiberty')
-rw-r--r-- | libiberty/rust-demangle.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c index 36afcfa..d6daf23 100644 --- a/libiberty/rust-demangle.c +++ b/libiberty/rust-demangle.c @@ -1082,6 +1082,18 @@ demangle_path_maybe_open_generics (struct rust_demangler *rdm) if (rdm->errored) return open; + if (rdm->recursion != RUST_NO_RECURSION_LIMIT) + { + ++ rdm->recursion; + if (rdm->recursion > RUST_MAX_RECURSION_COUNT) + { + /* FIXME: There ought to be a way to report + that the recursion limit has been reached. */ + rdm->errored = 1; + goto end_of_func; + } + } + if (eat (rdm, 'B')) { backref = parse_integer_62 (rdm); @@ -1107,6 +1119,11 @@ demangle_path_maybe_open_generics (struct rust_demangler *rdm) } else demangle_path (rdm, 0); + + end_of_func: + if (rdm->recursion != RUST_NO_RECURSION_LIMIT) + -- rdm->recursion; + return open; } |