* Fix another Rust demangling bugs (PR 105039)
@ 2022-03-24 13:12 Nick Clifton
2022-06-26 18:35 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Nick Clifton @ 2022-03-24 13:12 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 271 bytes --]
Hi Guys,
Attached is a proposed patch to fix another Rust demangling bug
reported in PR 105039. I would like to say that this is the
last time that we will see this problem for the Rust demangler,
but I am not that naive...
OK to apply ?
Cheers
Nick
[-- Attachment #2: pr105039.patch --]
[-- Type: text/x-patch, Size: 1735 bytes --]
diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c
index 3b24d63892a..d601182ac50 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Fix another Rust demangling bugs (PR 105039)
2022-03-24 13:12 Fix another Rust demangling bugs (PR 105039) Nick Clifton
@ 2022-06-26 18:35 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2022-06-26 18:35 UTC (permalink / raw)
To: gcc-patches
On 3/24/2022 7:12 AM, Nick Clifton via Gcc-patches wrote:
> Hi Guys,
>
> Attached is a proposed patch to fix another Rust demangling bug
> reported in PR 105039. I would like to say that this is the
> last time that we will see this problem for the Rust demangler,
> but I am not that naive...
>
> OK to apply ?
OK.
There are days when I wonder if restructuring the demanglers to use
loops or gotos to avoid the recursion would be a step forward. But I'm
not convinced the same kinds of inputs just hang rather than eating
stack space until the limit is exhausted. So it wouldn't be a
significant QOI improvement.
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-26 18:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 13:12 Fix another Rust demangling bugs (PR 105039) Nick Clifton
2022-06-26 18:35 ` Jeff Law
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).