teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0001-Fix-regression-wrt-Lua-reinitialization-RhBug-195809.patch

Panu Matilainen d0c513
From 13c96b26978953aff17bd642328d249820214b12 Mon Sep 17 00:00:00 2001
Panu Matilainen d0c513
Message-Id: <13c96b26978953aff17bd642328d249820214b12.1620391180.git.pmatilai@redhat.com>
Panu Matilainen d0c513
From: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen d0c513
Date: Fri, 7 May 2021 15:10:13 +0300
Panu Matilainen d0c513
Subject: [PATCH] Fix regression wrt Lua reinitialization (RhBug:1958095)
Panu Matilainen d0c513
Panu Matilainen d0c513
Commit 2579d3e5ad5d713f2c161b9fb4835366ea4ea291 started storing the Lua
Panu Matilainen d0c513
context in the spec, but this leads to problems as what is actually a
Panu Matilainen d0c513
global context is now stored in two places, and can get out of sync.
Panu Matilainen d0c513
So if you parse a spec, and then reset the global context, you get a
Panu Matilainen d0c513
fancy segfault when the freeing the spec because it's pointing to
Panu Matilainen d0c513
la-la-lua land.
Panu Matilainen d0c513
Panu Matilainen d0c513
Revert back to always using the global Lua handle.
Panu Matilainen d0c513
---
Panu Matilainen d0c513
 build/parsePreamble.c     | 3 ++-
Panu Matilainen d0c513
 build/rpmbuild_internal.h | 1 -
Panu Matilainen d0c513
 build/spec.c              | 4 ++--
Panu Matilainen d0c513
 build/speclua.c           | 2 +-
Panu Matilainen d0c513
 tests/rpmpython.at        | 7 ++++++-
Panu Matilainen d0c513
 5 files changed, 11 insertions(+), 6 deletions(-)
Panu Matilainen d0c513
Panu Matilainen d0c513
diff --git a/build/parsePreamble.c b/build/parsePreamble.c
Panu Matilainen d0c513
index fc4a2994d..ac3d9159e 100644
Panu Matilainen d0c513
--- a/build/parsePreamble.c
Panu Matilainen d0c513
+++ b/build/parsePreamble.c
Panu Matilainen d0c513
@@ -321,7 +321,8 @@ int addSource(rpmSpec spec, int specline, const char *srcname, rpmTagVal tag)
Panu Matilainen d0c513
     rpmPushMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
Panu Matilainen d0c513
     free(buf);
Panu Matilainen d0c513
 
Panu Matilainen d0c513
-    addLuaSource(spec->lua, p);
Panu Matilainen d0c513
+    rpmlua lua = rpmluaGetGlobalState();
Panu Matilainen d0c513
+    addLuaSource(lua, p);
Panu Matilainen d0c513
 
Panu Matilainen d0c513
     if (!nofetch && tryDownload(p))
Panu Matilainen d0c513
 	return RPMRC_FAIL;
Panu Matilainen d0c513
diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h
Panu Matilainen d0c513
index 2bac303c7..39a9c916f 100644
Panu Matilainen d0c513
--- a/build/rpmbuild_internal.h
Panu Matilainen d0c513
+++ b/build/rpmbuild_internal.h
Panu Matilainen d0c513
@@ -138,7 +138,6 @@ struct rpmSpec_s {
Panu Matilainen d0c513
     Package sourcePackage;
Panu Matilainen d0c513
 
Panu Matilainen d0c513
     rpmMacroContext macros;
Panu Matilainen d0c513
-    rpmlua lua;
Panu Matilainen d0c513
     rpmstrPool pool;
Panu Matilainen d0c513
 
Panu Matilainen d0c513
     StringBuf prep;		/*!< %prep scriptlet. */
Panu Matilainen d0c513
diff --git a/build/spec.c b/build/spec.c
Panu Matilainen d0c513
index 365ce6d32..6a13afda2 100644
Panu Matilainen d0c513
--- a/build/spec.c
Panu Matilainen d0c513
+++ b/build/spec.c
Panu Matilainen d0c513
@@ -249,7 +249,7 @@ rpmSpec newSpec(void)
Panu Matilainen d0c513
     spec->macros = rpmGlobalMacroContext;
Panu Matilainen d0c513
     spec->pool = rpmstrPoolCreate();
Panu Matilainen d0c513
     
Panu Matilainen d0c513
-    spec->lua = specLuaInit(spec);
Panu Matilainen d0c513
+    specLuaInit(spec);
Panu Matilainen d0c513
     return spec;
Panu Matilainen d0c513
 }
Panu Matilainen d0c513
 
Panu Matilainen d0c513
@@ -298,7 +298,7 @@ rpmSpec rpmSpecFree(rpmSpec spec)
Panu Matilainen d0c513
 
Panu Matilainen d0c513
     // only destroy lua tables if there are no BASpecs left
Panu Matilainen d0c513
     if (spec->recursing || spec->BACount == 0) {
Panu Matilainen d0c513
-	spec->lua = specLuaFini(spec);
Panu Matilainen d0c513
+	specLuaFini(spec);
Panu Matilainen d0c513
     }
Panu Matilainen d0c513
 
Panu Matilainen d0c513
     spec->sources = freeSources(spec->sources);
Panu Matilainen d0c513
diff --git a/build/speclua.c b/build/speclua.c
Panu Matilainen d0c513
index 595d71f14..abf2a4886 100644
Panu Matilainen d0c513
--- a/build/speclua.c
Panu Matilainen d0c513
+++ b/build/speclua.c
Panu Matilainen d0c513
@@ -25,7 +25,7 @@ void * specLuaInit(rpmSpec spec)
Panu Matilainen d0c513
 
Panu Matilainen d0c513
 void * specLuaFini(rpmSpec spec)
Panu Matilainen d0c513
 {
Panu Matilainen d0c513
-    rpmlua lua = spec->lua;
Panu Matilainen d0c513
+    rpmlua lua = rpmluaGetGlobalState();
Panu Matilainen d0c513
     lua_State *L = rpmluaGetLua(lua);
Panu Matilainen d0c513
     for (const char **vp = luavars; vp && *vp; vp++) {
Panu Matilainen d0c513
 	lua_pushnil(L);
Panu Matilainen d0c513
diff --git a/tests/rpmpython.at b/tests/rpmpython.at
Panu Matilainen d0c513
index 14c6a75dc..8128263e3 100644
Panu Matilainen d0c513
--- a/tests/rpmpython.at
Panu Matilainen d0c513
+++ b/tests/rpmpython.at
Panu Matilainen d0c513
@@ -67,7 +67,7 @@ for iot in [ 'fpio', 'fdio', 'ufdio', 'gzdio' ]:
Panu Matilainen d0c513
 ],
Panu Matilainen d0c513
 [])
Panu Matilainen d0c513
 
Panu Matilainen d0c513
-RPMPY_TEST([spec parse],[
Panu Matilainen d0c513
+RPMPY_TEST([spec parse 1],[
Panu Matilainen d0c513
 # TODO: add a better test spec with sub-packages etc
Panu Matilainen d0c513
 spec = rpm.spec('${RPMDATA}/SPECS/hello.spec')
Panu Matilainen d0c513
 for (name, num, flags) in spec.sources:
Panu Matilainen d0c513
@@ -82,6 +82,11 @@ hello-1.0-1
Panu Matilainen d0c513
 hello-1.0-1
Panu Matilainen d0c513
 ])
Panu Matilainen d0c513
 
Panu Matilainen d0c513
+RPMPY_TEST([spec parse 2],[
Panu Matilainen d0c513
+spec = rpm.spec('${RPMDATA}/SPECS/mini.spec')
Panu Matilainen d0c513
+rpm.reloadConfig()
Panu Matilainen d0c513
+])
Panu Matilainen d0c513
+
Panu Matilainen d0c513
 RPMPY_TEST([basic header manipulation],[
Panu Matilainen d0c513
 h = rpm.hdr()
Panu Matilainen d0c513
 h['name'] = 'testpkg'
Panu Matilainen d0c513
-- 
Panu Matilainen d0c513
2.30.2
Panu Matilainen d0c513