From d0c51399dced2fa2ab1e5d3af3705823c8848309 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 7 May 2021 15:47:25 +0300 Subject: [PATCH] Fix regression causing a crash on Lua state reset (#1958095) Also move previously misplaced previous patch to the "already upstream" section. --- ...rt-Lua-reinitialization-RhBug-195809.patch | 111 ++++++++++++++++++ rpm.spec | 9 +- 2 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 0001-Fix-regression-wrt-Lua-reinitialization-RhBug-195809.patch diff --git a/0001-Fix-regression-wrt-Lua-reinitialization-RhBug-195809.patch b/0001-Fix-regression-wrt-Lua-reinitialization-RhBug-195809.patch new file mode 100644 index 0000000..ab69faf --- /dev/null +++ b/0001-Fix-regression-wrt-Lua-reinitialization-RhBug-195809.patch @@ -0,0 +1,111 @@ +From 13c96b26978953aff17bd642328d249820214b12 Mon Sep 17 00:00:00 2001 +Message-Id: <13c96b26978953aff17bd642328d249820214b12.1620391180.git.pmatilai@redhat.com> +From: Panu Matilainen +Date: Fri, 7 May 2021 15:10:13 +0300 +Subject: [PATCH] Fix regression wrt Lua reinitialization (RhBug:1958095) + +Commit 2579d3e5ad5d713f2c161b9fb4835366ea4ea291 started storing the Lua +context in the spec, but this leads to problems as what is actually a +global context is now stored in two places, and can get out of sync. +So if you parse a spec, and then reset the global context, you get a +fancy segfault when the freeing the spec because it's pointing to +la-la-lua land. + +Revert back to always using the global Lua handle. +--- + build/parsePreamble.c | 3 ++- + build/rpmbuild_internal.h | 1 - + build/spec.c | 4 ++-- + build/speclua.c | 2 +- + tests/rpmpython.at | 7 ++++++- + 5 files changed, 11 insertions(+), 6 deletions(-) + +diff --git a/build/parsePreamble.c b/build/parsePreamble.c +index fc4a2994d..ac3d9159e 100644 +--- a/build/parsePreamble.c ++++ b/build/parsePreamble.c +@@ -321,7 +321,8 @@ int addSource(rpmSpec spec, int specline, const char *srcname, rpmTagVal tag) + rpmPushMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC); + free(buf); + +- addLuaSource(spec->lua, p); ++ rpmlua lua = rpmluaGetGlobalState(); ++ addLuaSource(lua, p); + + if (!nofetch && tryDownload(p)) + return RPMRC_FAIL; +diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h +index 2bac303c7..39a9c916f 100644 +--- a/build/rpmbuild_internal.h ++++ b/build/rpmbuild_internal.h +@@ -138,7 +138,6 @@ struct rpmSpec_s { + Package sourcePackage; + + rpmMacroContext macros; +- rpmlua lua; + rpmstrPool pool; + + StringBuf prep; /*!< %prep scriptlet. */ +diff --git a/build/spec.c b/build/spec.c +index 365ce6d32..6a13afda2 100644 +--- a/build/spec.c ++++ b/build/spec.c +@@ -249,7 +249,7 @@ rpmSpec newSpec(void) + spec->macros = rpmGlobalMacroContext; + spec->pool = rpmstrPoolCreate(); + +- spec->lua = specLuaInit(spec); ++ specLuaInit(spec); + return spec; + } + +@@ -298,7 +298,7 @@ rpmSpec rpmSpecFree(rpmSpec spec) + + // only destroy lua tables if there are no BASpecs left + if (spec->recursing || spec->BACount == 0) { +- spec->lua = specLuaFini(spec); ++ specLuaFini(spec); + } + + spec->sources = freeSources(spec->sources); +diff --git a/build/speclua.c b/build/speclua.c +index 595d71f14..abf2a4886 100644 +--- a/build/speclua.c ++++ b/build/speclua.c +@@ -25,7 +25,7 @@ void * specLuaInit(rpmSpec spec) + + void * specLuaFini(rpmSpec spec) + { +- rpmlua lua = spec->lua; ++ rpmlua lua = rpmluaGetGlobalState(); + lua_State *L = rpmluaGetLua(lua); + for (const char **vp = luavars; vp && *vp; vp++) { + lua_pushnil(L); +diff --git a/tests/rpmpython.at b/tests/rpmpython.at +index 14c6a75dc..8128263e3 100644 +--- a/tests/rpmpython.at ++++ b/tests/rpmpython.at +@@ -67,7 +67,7 @@ for iot in [ 'fpio', 'fdio', 'ufdio', 'gzdio' ]: + ], + []) + +-RPMPY_TEST([spec parse],[ ++RPMPY_TEST([spec parse 1],[ + # TODO: add a better test spec with sub-packages etc + spec = rpm.spec('${RPMDATA}/SPECS/hello.spec') + for (name, num, flags) in spec.sources: +@@ -82,6 +82,11 @@ hello-1.0-1 + hello-1.0-1 + ]) + ++RPMPY_TEST([spec parse 2],[ ++spec = rpm.spec('${RPMDATA}/SPECS/mini.spec') ++rpm.reloadConfig() ++]) ++ + RPMPY_TEST([basic header manipulation],[ + h = rpm.hdr() + h['name'] = 'testpkg' +-- +2.30.2 + diff --git a/rpm.spec b/rpm.spec index 332e15b..ed4a573 100644 --- a/rpm.spec +++ b/rpm.spec @@ -32,7 +32,7 @@ %global rpmver 4.16.90 %global snapver git15395 -%global rel 5 +%global rel 6 %global sover 9 %global srcver %{rpmver}%{?snapver:-%{snapver}} @@ -54,9 +54,9 @@ Patch3: rpm-4.9.90-no-man-dirs.patch # https://github.com/rpm-software-management/rpm/pull/473 Patch6: 0001-find-debuginfo.sh-decompress-DWARF-compressed-ELF-se.patch -Patch10: 0001-Ignore-comment-line-contents-in-macro-files-1659.patch - # Patches already upstream: +Patch100: 0001-Ignore-comment-line-contents-in-macro-files-1659.patch +Patch101: 0001-Fix-regression-wrt-Lua-reinitialization-RhBug-195809.patch # These are not yet upstream Patch906: rpm-4.7.1-geode-i686.patch @@ -571,6 +571,9 @@ fi %doc doc/librpm/html/* %changelog +* Fri May 07 2021 Panu Matilainen - 4.16.90-0.git15395.6 +- Fix regression causing a crash on Lua state reset (#1958095) + * Thu Apr 29 2021 Panu Matilainen - 4.16.90-0.git15395.5 - Proper fix for comments affecting macro file parsing (#1953910)