public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Nick Clifton <nickc@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1393] Add a recursion limit to the demangle_const function in the Rust demangler. Date: Fri, 1 Jul 2022 15:00:26 +0000 (GMT) [thread overview] Message-ID: <20220701150026.D43A93858D28@sourceware.org> (raw) https://gcc.gnu.org/g:9234cdca6ee88badfc00297e72f13dac4e540c79 commit r13-1393-g9234cdca6ee88badfc00297e72f13dac4e540c79 Author: Nick Clifton <nickc@redhat.com> Date: Fri Jul 1 15:58:52 2022 +0100 Add a recursion limit to the demangle_const function in the Rust demangler. libiberty/ PR demangler/105039 * rust-demangle.c (demangle_const): Add recursion limit. Diff: --- libiberty/rust-demangle.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c index bb58d900e27..36afcfae278 100644 --- a/libiberty/rust-demangle.c +++ b/libiberty/rust-demangle.c @@ -126,7 +126,7 @@ parse_integer_62 (struct rust_demangler *rdm) return 0; x = 0; - while (!eat (rdm, '_')) + while (!eat (rdm, '_') && !rdm->errored) { c = next (rdm); x *= 62; @@ -1148,6 +1148,15 @@ demangle_const (struct rust_demangler *rdm) if (rdm->errored) return; + 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. */ + goto fail_return; + } + if (eat (rdm, 'B')) { backref = parse_integer_62 (rdm); @@ -1158,7 +1167,7 @@ demangle_const (struct rust_demangler *rdm) demangle_const (rdm); rdm->next = old_next; } - return; + goto pass_return; } ty_tag = next (rdm); @@ -1167,7 +1176,7 @@ demangle_const (struct rust_demangler *rdm) /* Placeholder. */ case 'p': PRINT ("_"); - return; + goto pass_return; /* Unsigned integer types. */ case 'h': @@ -1200,18 +1209,20 @@ demangle_const (struct rust_demangler *rdm) break; default: - rdm->errored = 1; - return; + goto fail_return; } - if (rdm->errored) - return; - - if (rdm->verbose) + if (!rdm->errored && rdm->verbose) { PRINT (": "); PRINT (basic_type (ty_tag)); } + + fail_return: + rdm->errored = 1; + pass_return: + if (rdm->recursion != RUST_NO_RECURSION_LIMIT) + -- rdm->recursion; } static void
reply other threads:[~2022-07-01 15:00 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220701150026.D43A93858D28@sourceware.org \ --to=nickc@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).