From 0ae9b336476cfc4291411bc004c79d554e32b83d Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 15 Dec 2023 14:25:11 +0200 Subject: [PATCH] Fix bogus warnings about runaway Lua scripts (#2254463) --- ...n-Lua-scriptlet-runaway-child-detect.patch | 79 +++++++++++++++++++ rpm.spec | 6 +- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 0001-Fix-regression-in-Lua-scriptlet-runaway-child-detect.patch diff --git a/0001-Fix-regression-in-Lua-scriptlet-runaway-child-detect.patch b/0001-Fix-regression-in-Lua-scriptlet-runaway-child-detect.patch new file mode 100644 index 0000000..40c0c5e --- /dev/null +++ b/0001-Fix-regression-in-Lua-scriptlet-runaway-child-detect.patch @@ -0,0 +1,79 @@ +From bb4aaaa2e8e4bdfc02f9d98ab2982074051c4eb2 Mon Sep 17 00:00:00 2001 +Message-ID: +From: Panu Matilainen +Date: Fri, 15 Dec 2023 13:15:29 +0200 +Subject: [PATCH] Fix regression in Lua scriptlet runaway child detection + +Commit a8107659ef3dd4855729bf65aa4d70f784cb5a5f moved the detection +to parent using waitpid(), but this causes it to complain on any +process in the same process group. In the usual rpm context we don't +have any, but we can't very well tell API users not to have any +children. And then failed to detect a runaway Lua child in one of +our own tests. Uff. + +rpmlog() in the child has the issues mentioned in the originating +commit, but that's a problem that needs to be solved elsewhere. +Revert back to issuing a warning when we actually *are* in the child +process, so there are no false positive possible. Use EXIT_FAILURE +like in the original version, dunno why I'd changed that. + +Update the rpmlua test to expect the deserved warning, and use +stdio for printing its "normal" output, the catch there is that we +need to flush the io in the child. + +Reported at https://bugzilla.redhat.com/show_bug.cgi?id=2254463 +--- + rpmio/rpmlua.c | 10 +++------- + tests/rpmmacro.at | 9 ++++----- + 2 files changed, 7 insertions(+), 12 deletions(-) + +diff --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c +index 8ef90e779..854fd469d 100644 +--- a/rpmio/rpmlua.c ++++ b/rpmio/rpmlua.c +@@ -239,17 +239,13 @@ static int luaopt(int c, const char *oarg, int oint, void *data) + static int rpm_pcall(lua_State *L, int nargs, int nresults, int errfunc) + { + pid_t pid = getpid(); +- int status; + + int rc = lua_pcall(L, nargs, nresults, errfunc); + + /* Terminate unhandled fork from Lua script */ +- if (pid != getpid()) +- _exit(1); +- +- if (waitpid(0, &status, WNOHANG) == 0) { +- rpmlog(RPMLOG_WARNING, +- _("runaway fork() in Lua script\n")); ++ if (pid != getpid()) { ++ rpmlog(RPMLOG_WARNING, _("runaway fork() in Lua script\n")); ++ _exit(EXIT_FAILURE); + } + + return rc; +diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at +index 0ebcc050c..47a13ef2b 100644 +--- a/tests/rpmmacro.at ++++ b/tests/rpmmacro.at +@@ -1322,13 +1322,12 @@ nil No such file or directory 2.0 + ], + []) + +-# This uses io.stderr:write() because the grue from the previous test +-# appears to have eaten stdout of the forked child, or something. + RPMTEST_CHECK([ +-runroot_other rpmlua -e 'pid = posix.fork(); if pid == 0 then a,b,c=rpm.redirect2null(-1); io.stderr:write(string.format("%s\t%s\t%s\n", a,b,c)) else posix.wait(pid) end' ++runroot_other rpmlua -e 'pid = posix.fork(); if pid == 0 then a,b,c=rpm.redirect2null(-1); print(string.format("%s\t%s\t%s", a,b,c)); io.flush() else posix.wait(pid) end' + ], + [0], +-[], + [nil Bad file descriptor 9.0 +-]) ++], ++[warning: runaway fork() in Lua script] ++) + RPMTEST_CLEANUP +-- +2.43.0 + diff --git a/rpm.spec b/rpm.spec index 37cde3a..f7320c3 100644 --- a/rpm.spec +++ b/rpm.spec @@ -27,7 +27,7 @@ %global rpmver 4.19.1 #global snapver rc1 -%global baserelease 1 +%global baserelease 2 %global sover 10 %global srcver %{rpmver}%{?snapver:-%{snapver}} @@ -139,6 +139,7 @@ rpm-4.18.92-disable-sysusers.patch rpm-4.18.90-weak-user-group.patch # Patches already upstream: +0001-Fix-regression-in-Lua-scriptlet-runaway-child-detect.patch # ... # These are not yet upstream @@ -619,6 +620,9 @@ fi %doc %{_defaultdocdir}/rpm/API/ %changelog +* Fri Dec 15 2023 Panu Matilainen - 4.19.1-2 +- Fix bogus warnings about runaway Lua scripts (#2254463) + * Tue Dec 12 2023 Michal Domonkos - 4.19.1-1 - Update to 4.19.1 (https://rpm.org/wiki/Releases/4.19.1)