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.
This commit is contained in:
Nick Clifton 2022-07-04 11:05:03 +01:00
parent 4e82205b68
commit 1a770b01ef

View file

@ -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;
}