From 9e868de349c9fa32485f89547744afeb75a4bdcd Mon Sep 17 00:00:00 2001 From: Guinevere Larsen Date: Tue, 10 Oct 2023 13:51:40 +0200 Subject: [PATCH] Backport "Add a recursion limit to the demangle_const function in the Rust demangler." And related patches. Also fix bogus date on changelog Resolves: RHEL-7330 --- _gdb.spec.Patch.include | 8 ++ _gdb.spec.patch.include | 2 + _patch_order | 2 + gdb.spec | 8 +- libiberty-infinite-recursion-fix-1-of-2.patch | 85 +++++++++++++++++++ libiberty-infinite-recursion-fix-2-of-2.patch | 23 +++++ 6 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 libiberty-infinite-recursion-fix-1-of-2.patch create mode 100644 libiberty-infinite-recursion-fix-2-of-2.patch diff --git a/_gdb.spec.Patch.include b/_gdb.spec.Patch.include index 3c93a0a..61c0d88 100644 --- a/_gdb.spec.Patch.include +++ b/_gdb.spec.Patch.include @@ -293,3 +293,11 @@ Patch068: gdb-backport-call-check_typedef-at-beginning-of-dwarf_expr_context.pat # (Nick Clifton, RHBZ 2153228) Patch069: gdb-rhbz2153228-fail-if-sh_info-is-zero.patch +# Backport Add a recursion limit to the demangle_const function in the Rust demangler. +# (Nick Clifton, RHEL-4234) +Patch070: libiberty-infinite-recursion-fix-1-of-2.patch + +# Backport Fix typo in recent code to add stack recursion limit to the Rust demangler. +# (Nick Clifton) +Patch071: libiberty-infinite-recursion-fix-2-of-2.patch + diff --git a/_gdb.spec.patch.include b/_gdb.spec.patch.include index 4ef8e6c..56e7473 100644 --- a/_gdb.spec.patch.include +++ b/_gdb.spec.patch.include @@ -67,3 +67,5 @@ %patch067 -p1 %patch068 -p1 %patch069 -p1 +%patch070 -p1 +%patch071 -p1 diff --git a/_patch_order b/_patch_order index 0a0491b..49e8ddc 100644 --- a/_patch_order +++ b/_patch_order @@ -67,3 +67,5 @@ gdb-backport-python-config-replace-deprecated-distutils.patch gdb-gcc-13-backport-self-move-diagnostic-fix gdb-backport-call-check_typedef-at-beginning-of-dwarf_expr_context.patch gdb-rhbz2153228-fail-if-sh_info-is-zero.patch +libiberty-infinite-recursion-fix-1-of-2.patch +libiberty-infinite-recursion-fix-2-of-2.patch diff --git a/gdb.spec b/gdb.spec index c32c1e3..5a5e5a1 100644 --- a/gdb.spec +++ b/gdb.spec @@ -73,7 +73,7 @@ Version: 12.1 # The release always contains a leading reserved number, start it at 1. # `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing. -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and LGPLv3+ and BSD and Public Domain and GFDL # Do not provide URL for snapshots as the file lasts there only for 2 days. @@ -1205,6 +1205,12 @@ fi %endif %changelog +* Tue Oct 10 2023 Guinevere Larsen - 12.1-4.el9 +- Backport "Fix typo in recent code to add stack recursion limit to the Rust demangler." + (Nick Clifton) +- Backport "Add a recursion limit to the demangle_const function in the Rust demangler." + (Nick Clifton, RHEL-4234) + * Tue Jun 13 2023 Keith Seitz - 12.1-3.el9 - Backport "Update gdb-add-index.sh ..." (Andrew Burgess, RHBZ 2213228) diff --git a/libiberty-infinite-recursion-fix-1-of-2.patch b/libiberty-infinite-recursion-fix-1-of-2.patch new file mode 100644 index 0000000..4acf718 --- /dev/null +++ b/libiberty-infinite-recursion-fix-1-of-2.patch @@ -0,0 +1,85 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: Nick Clifton +Date: Fri, 1 Jul 2022 15:58:52 +0100 +Subject: libiberty-infinite-recursion-fix-1-of-2.patch + +;; Backport Add a recursion limit to the demangle_const function in the Rust demangler. +;; (Nick Clifton, RHEL-4234) + +libiberty/ + PR demangler/105039 + * rust-demangle.c (demangle_const): Add recursion limit. + +diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c +--- 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 diff --git a/libiberty-infinite-recursion-fix-2-of-2.patch b/libiberty-infinite-recursion-fix-2-of-2.patch new file mode 100644 index 0000000..91deb76 --- /dev/null +++ b/libiberty-infinite-recursion-fix-2-of-2.patch @@ -0,0 +1,23 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: Nick Clifton +Date: Mon, 4 Jul 2022 16:31:18 +0100 +Subject: libiberty-infinite-recursion-fix-2-of-2.patch + +;; Backport Fix typo in recent code to add stack recursion limit to the Rust demangler. +;; (Nick Clifton) + +libiberty + * rust-demangle.c (demangle_const): Add a missing goto pass_return + at the end of the function. + +diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c +--- a/libiberty/rust-demangle.c ++++ b/libiberty/rust-demangle.c +@@ -1217,6 +1217,7 @@ demangle_const (struct rust_demangler *rdm) + PRINT (": "); + PRINT (basic_type (ty_tag)); + } ++ goto pass_return; + + fail_return: + rdm->errored = 1;