diff --git a/backport-Fix-division-by-zero-in-elfdeps-RhBug-2299414.patch b/backport-Fix-division-by-zero-in-elfdeps-RhBug-2299414.patch new file mode 100644 index 0000000..48b114e --- /dev/null +++ b/backport-Fix-division-by-zero-in-elfdeps-RhBug-2299414.patch @@ -0,0 +1,30 @@ +From 02ffc5158d1ad270e0b5c7ce6dfe4414a6ec029f Mon Sep 17 00:00:00 2001 +From: Michal Domonkos +Date: Wed, 31 Jul 2024 16:19:40 +0200 +Subject: [PATCH] Fix division by zero in elfdeps (RhBug:2299414) + +Conflict:NA +Reference:https://github.com/rpm-software-management/rpm/commit/02ffc5158d1ad270e0b5c7ce6dfe4414a6ec029f + +Assume that the section does not hold a table if sh_entsize is 0 (as +specified in the elf(5) man page) and just skip it if that's the case. +--- + tools/elfdeps.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/tools/elfdeps.c b/tools/elfdeps.c +index cb388f08d..822359ab9 100644 +--- a/tools/elfdeps.c ++++ b/tools/elfdeps.c +@@ -196,6 +196,8 @@ static void processVerNeed(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei) + static void processDynamic(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei) + { + Elf_Data *data = NULL; ++ if (shdr->sh_entsize == 0) ++ return; + while ((data = elf_getdata(scn, data)) != NULL) { + for (int i = 0; i < (shdr->sh_size / shdr->sh_entsize); i++) { + const char *s = NULL; +-- +2.33.0 + diff --git a/backport-Fix-macro-scoping-level-on-re-entry-from-expresssion.patch b/backport-Fix-macro-scoping-level-on-re-entry-from-expresssion.patch new file mode 100644 index 0000000..3cdfa68 --- /dev/null +++ b/backport-Fix-macro-scoping-level-on-re-entry-from-expresssion.patch @@ -0,0 +1,110 @@ +From fd2f743b3ef543a5b6fe963b2ec8c3c43b8424b9 Mon Sep 17 00:00:00 2001 +From: Panu Matilainen +Date: Thu, 19 Jan 2023 09:55:14 +0200 +Subject: [PATCH] Fix macro scoping level on re-entry from %[] expresssion + (#2354) +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Conflict:NA +Reference:https://github.com/rpm-software-management/rpm/commit/fd2f743b3ef543a5b6fe963b2ec8c3c43b8424b9 + +This is the same issue as commit 1767bc4fd82bfacee622e698f9f0ae42c02126fa +was with Lua, and so the same fix works: restore the nesting level +from the macro context when re-entering macro engine from %[] +expression. Analysis and suggested fix by Michael Schroeder, +reproducer from Miro Hrončok. + +Add tests for both %[] and %{expr:...}, although the latter isn't +affected because the expression is macro-expanded beforehand. + +Fixes: #2354 +--- + rpmio/macro.c | 13 +++++++++++-- + tests/rpmmacro.at | 37 +++++++++++++++++++++++++++++++++++++ + 2 files changed, 48 insertions(+), 2 deletions(-) + +diff --git a/rpmio/macro.c b/rpmio/macro.c +index 2a00c22b3..d86b84608 100644 +--- a/rpmio/macro.c ++++ b/rpmio/macro.c +@@ -58,8 +58,8 @@ struct rpmMacroEntry_s { + struct rpmMacroContext_s { + rpmMacroEntry *tab; /*!< Macro entry table (array of pointers). */ + int n; /*!< No. of macros. */ +- int depth; /*!< Depth tracking when recursing from Lua */ +- int level; /*!< Scope level tracking when recursing from Lua */ ++ int depth; /*!< Depth tracking on external recursion */ ++ int level; /*!< Scope level tracking when on external recursion */ + pthread_mutex_t lock; + pthread_mutexattr_t lockattr; + }; +@@ -586,7 +586,16 @@ static void doExpressionExpansion(MacroBuf mb, const char * expr, size_t len) + { + char *buf = rstrndup(expr, len); + char *result; ++ rpmMacroContext mc = mb->mc; ++ int odepth = mc->depth; ++ int olevel = mc->level; ++ ++ mc->depth = mb->depth; ++ mc->level = mb->level; + result = rpmExprStrFlags(buf, RPMEXPR_EXPAND); ++ mc->depth = odepth; ++ mc->level = olevel; ++ + if (!result) { + mb->error = 1; + goto exit; +diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at +index 2a3052cca..55b7d5fa5 100644 +--- a/tests/rpmmacro.at ++++ b/tests/rpmmacro.at +@@ -526,6 +526,43 @@ runroot rpm \ + []) + AT_CLEANUP + ++AT_SETUP([expression macro level]) ++AT_KEYWORDS([macros]) ++AT_CHECK([[ ++runroot rpm \ ++ --define 'expopt(r) %[%{undefined yyy} ? "aa " : "bb "]%{-r:the -r option was set}%{!-r:the -r option was not set}' \ ++ --eval '%expopt' \ ++ --eval '%expopt -r' \ ++ --define 'yyy 1' \ ++ --eval '%expopt' \ ++ --eval '%expopt -r' ++]], ++[0], ++[aa the -r option was not set ++aa the -r option was set ++bb the -r option was not set ++bb the -r option was set ++], ++[]) ++ ++AT_CHECK([[ ++runroot rpm \ ++ --define 'expopt(r) %{expr:%{undefined yyy} ? "aa " : "bb "}%{-r:the -r option was set}%{!-r:the -r option was not set}' \ ++ --eval '%expopt' \ ++ --eval '%expopt -r' \ ++ --define 'yyy 1' \ ++ --eval '%expopt' \ ++ --eval '%expopt -r' ++]], ++[0], ++[aa the -r option was not set ++aa the -r option was set ++bb the -r option was not set ++bb the -r option was set ++], ++[]) ++AT_CLEANUP ++ + AT_SETUP([short circuiting]) + AT_KEYWORDS([macros]) + AT_CHECK([ +-- +2.33.0 + diff --git a/backport-Reset-recursion-depth-for-error-message.patch b/backport-Reset-recursion-depth-for-error-message.patch new file mode 100644 index 0000000..0f2053e --- /dev/null +++ b/backport-Reset-recursion-depth-for-error-message.patch @@ -0,0 +1,82 @@ +From ef87d2503498f65577b5d7af07cd453d622fe02c Mon Sep 17 00:00:00 2001 +From: Florian Festi +Date: Thu, 18 Jul 2024 13:04:28 +0200 +Subject: [PATCH] Reset recursion depth for error message +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Conflict:adapt context; use AT_{CHECK,CLEANUP} instead of RPMTEST_{CHECK,CLEANUP} + because adafe8d04724b is ont merged +Reference:https://github.com/rpm-software-management/rpm/commit/ef87d2503498f65577b5d7af07cd453d622fe02c + +$ rpm --define 'aaa %[%aaa]' --eval '%aaa' + +let to a core dump due to a stack overflow. This was cause by the +generation of the error message failing due to being too deep in the +recursion of the macro expansion - creating more error messages. + +Resetting the depth counter allows rendering the error message. As we are +failing and breaking off the parse run this is fine to do. + +Thanks to Miro Hrončok for reporting + +Resolves: #3197 +--- + rpmio/macro.c | 4 +++- + tests/rpmmacro.at | 22 ++++++++++++++++++++++ + 2 files changed, 25 insertions(+), 1 deletion(-) + +diff --git a/rpmio/macro.c b/rpmio/macro.c +index b2fb1326d..3f34f718e 100644 +--- a/rpmio/macro.c ++++ b/rpmio/macro.c +@@ -447,9 +447,11 @@ static int mbInit(rpmMacroBuf mb, MacroExpansionData *med, size_t slen) + if (mb->buf == NULL) + mbAllocBuf(mb, slen); + if (++mb->depth > max_macro_depth) { ++ mb->depth--; ++ /* ensure error message can be rendered */ ++ mb->mc->depth = 0; + mbErr(mb, 1, + _("Too many levels of recursion in macro expansion. It is likely caused by recursive macro declaration.\n")); +- mb->depth--; + return -1; + } + med->tpos = mb->tpos; /* save expansion pointer for printExpand */ +diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at +index 372cfa3ed..3adf48b61 100644 +--- a/tests/rpmmacro.at ++++ b/tests/rpmmacro.at +@@ -133,6 +133,28 @@ runroot rpm --define "this that" --define "that_that foo" --eval '%{expand:%{%{t + ]) + AT_CLEANUP + ++AT_SETUP([recursive macro]) ++AT_KEYWORDS([macros]) ++AT_CHECK([ ++runroot rpm --define 'aaa %aaa' --eval '%aaa' ++], ++[1], ++[], ++[error: Too many levels of recursion in macro expansion. It is likely caused by recursive macro declaration. ++]) ++AT_CLEANUP ++ ++AT_SETUP([recursive expression]) ++AT_KEYWORDS([macros]) ++AT_CHECK([ ++runroot rpm --define 'aaa %\\[%aaa\\]' --eval '%aaa' ++], ++[1], ++[], ++[error: Too many levels of recursion in macro expansion. It is likely caused by recursive macro declaration. ++]) ++AT_CLEANUP ++ + AT_SETUP([parametrized macro 1]) + AT_KEYWORDS([macros]) + AT_CHECK([ +-- +2.33.0 + diff --git a/rpm.spec b/rpm.spec index 95df1a7..82dd9b5 100644 --- a/rpm.spec +++ b/rpm.spec @@ -1,6 +1,6 @@ Name: rpm Version: 4.17.0 -Release: 43 +Release: 44 Summary: RPM Package Manager License: GPLv2+ URL: http://www.rpm.org/ @@ -125,6 +125,9 @@ Patch6093: backport-Fix-pointer-bogosity-in-rpmlog-callback.patch Patch6094: backport-Fix-an-ancient-memleak-on-caps-parsing-add-tests.patch Patch6095: backport-Fix-potential-use-of-uninitialized-pipe-array.patch Patch6096: backport-Fix-potential-use-of-uninitialized-pgp-struct.patch +Patch6097: backport-Fix-macro-scoping-level-on-re-entry-from-expresssion.patch +Patch6098: backport-Reset-recursion-depth-for-error-message.patch +Patch6099: backport-Fix-division-by-zero-in-elfdeps-RhBug-2299414.patch BuildRequires: gcc autoconf automake libtool make gawk popt-devel openssl-devel readline-devel BuildRequires: zlib-devel zstd-devel >= 1.3.8 xz-devel bzip2-devel libarchive-devel ima-evm-utils-devel @@ -415,6 +418,9 @@ make check || (cat tests/rpmtests.log; exit 0) %{_mandir}/man1/gendiff.1* %changelog +* Tue Sep 3 2024 gengqihu - 4.17.0-44 +- Backport some patches from upstream + * Thu Aug 22 2024 luhuaxin - 4.17.0-43 - Fix the calculation of hdr size