public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/python3-rpm] epel9: Fix rpopen()/rpclose() and make them more POSIXy
@ 2026-11-13 18:33 Michal Domonkos
0 siblings, 0 replies; only message in thread
From: Michal Domonkos @ 2026-11-13 18:33 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/python3-rpm
Branch : epel9
Commit : d08a98eb325d89c66ef506ec4513b3c3335f9527
Author : Michal Domonkos <mdomonko@redhat.com>
Date : 2026-11-09T16:03:29+01:00
Stats : +158/-1 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/python3-rpm/c/d08a98eb325d89c66ef506ec4513b3c3335f9527?branch=epel9
Log:
Fix rpopen()/rpclose() and make them more POSIXy
Related: RHEL-288157
---
diff --git a/0001-Fix-rpopen-rpclose-and-make-them-more-POSIXy.patch b/0001-Fix-rpopen-rpclose-and-make-them-more-POSIXy.patch
new file mode 100644
index 0000000..2028741
--- /dev/null
+++ b/0001-Fix-rpopen-rpclose-and-make-them-more-POSIXy.patch
@@ -0,0 +1,153 @@
+From c745bd8ee4b383897927eb2e504dba9b97aa7b03 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Tue, 3 Nov 2026 08:48:11 +0100
+Subject: [PATCH] Fix rpopen()/rpclose() and make them more POSIXy
+
+Commit 7a4111bc5db4053e5381b65306903837763e7f11 introduced this new pair
+of drop-in replacements for popen()/pclose() but did so somewhat poorly.
+Apart from obvious bugs, there are various less obvious issues that make
+the functions ever so slightly not POSIX conforming. We are not shipping
+them in a generic library, obviously, but the internal callers that used
+to call the original functions could, at least in theory, be affected in
+some unexpected ways and cause regressions.
+
+Namely, the following issues were found:
+
+- rpclose() returned the extracted exit status from the child instead of
+ the original status from waitpid(2), which caused a child exit status
+ of 128 to be considered a "success" in rpmuncompress, oops
+- rpclose() waited on any child, not just the one spawned with rpopen()
+- EINTR wasn't ignored while busy waiting in rpclose()
+- pipe ends weren't always closed in case of failures
+- rpclose() only closed the stream after waiting on the child
+- the child didn't return 127 if the shell couldn't be invoked
+- the shell command didn't use -- to signal the end of options
+
+Fix the issues, and while at it, name the FILE pointer "fp" rather than
+"stream" and use do-while rather than while, for better consistency with
+the existing code as well as readability. Also do some refactoring there
+and add a couple of comments.
+
+Related: CVE-2026-84837, CVE-2026-84838
+Fixes: #4385
+(cherry picked from commit b9127abde15ec1a5d936891f7d5f78ddc5b689ff)
+---
+ cliutils.c | 58 ++++++++++++++++++++++++++++++++----------------------
+ cliutils.h | 2 +-
+ 2 files changed, 36 insertions(+), 24 deletions(-)
+
+diff --git a/cliutils.c b/cliutils.c
+index 6547e7bdb..5edb9fea7 100644
+--- a/cliutils.c
++++ b/cliutils.c
+@@ -14,6 +14,7 @@
+ #include "debug.h"
+
+ static pid_t pipeChild = 0;
++static pid_t rpopenChild = 0;
+
+ RPM_GNUC_NORETURN
+ void argerror(const char * desc)
+@@ -89,53 +90,64 @@ int finishPipe(void)
+
+ FILE* rpopen(const char *cmd, const char *arg, ...)
+ {
+- FILE *stream = NULL;
++ FILE *fp = NULL;
++ int pipefd[2];
+ ARGV_t argv = NULL;
+ va_list ap;
+- int pipefd[2];
+- pid_t pid;
+
+ if (pipe(pipefd) < 0)
+- goto exit;
++ return NULL;
++
++ if ((fp = fdopen(pipefd[0], "r")) == NULL) {
++ close(pipefd[0]);
++ close(pipefd[1]);
++ return NULL;
++ }
+
+ argvAdd(&argv, "/bin/sh");
+ argvAdd(&argv, "-c");
+- argvAdd(&argv, cmd);
+- argvAdd(&argv, "sh");
++ argvAdd(&argv, "--");
++ argvAdd(&argv, cmd); /* User command */
++ argvAdd(&argv, "sh"); /* Shell name ($0) */
+
++ /* User positional parameters ($1, $2, ...) */
+ va_start(ap, arg);
+ for (const char *s = arg; s != NULL; s = va_arg(ap, const char *))
+ argvAdd(&argv, s);
+ va_end(ap);
+
+- if ((pid = fork()) == 0) {
++ if ((rpopenChild = fork()) == 0) {
+ dup2(pipefd[1], STDOUT_FILENO);
++ close(pipefd[1]);
+ close(pipefd[0]);
+ execv(argv[0], argv);
+- _exit(EXIT_FAILURE);
+- } else if (pid == -1) {
+- goto exit;
++ _exit(127);
++ } else if (rpopenChild == -1) {
++ fclose(fp);
++ fp = NULL;
+ }
+
+ close(pipefd[1]);
+- stream = fdopen(pipefd[0], "r");
+-
+-exit:
+ argvFree(argv);
+- return stream;
++
++ return fp;
+ }
+
+-int rpclose(FILE *stream)
++int rpclose(FILE *fp)
+ {
+- int rc = -1;
+- int status;
++ int status = -1;
++ pid_t reaped;
+
+- if ((waitpid(-1, &status, 0) == -1) || !WIFEXITED(status))
+- goto exit;
++ if (rpopenChild <= 0)
++ return -1;
+
+- rc = WEXITSTATUS(status);
++ fclose(fp);
++ do {
++ reaped = waitpid(rpopenChild, &status, 0);
++ } while (reaped == -1 && errno == EINTR);
+
+-exit:
+- fclose(stream);
+- return rc;
++ if (reaped == -1)
++ return -1;
++
++ return status;
+ }
+diff --git a/cliutils.h b/cliutils.h
+index 4aee1ae72..600ccfa95 100644
+--- a/cliutils.h
++++ b/cliutils.h
+@@ -28,6 +28,6 @@ int finishPipe(void);
+ * $2, and so on.
+ */
+ FILE *rpopen(const char *cmd, const char *arg, ...) RPM_GNUC_NULL_TERMINATED;
+-int rpclose(FILE *stream);
++int rpclose(FILE *fp);
+
+ #endif /* _CLIUTIL_H */
+--
+2.56.0
+
diff --git a/rpm.spec b/rpm.spec
index 4425a73..b15b4d5 100644
--- a/rpm.spec
+++ b/rpm.spec
@@ -32,7 +32,7 @@
%global rpmver 4.16.1.3
#global snapver rc1
-%global rel 42
+%global rel 43
%global sover 9
%global srcver %{rpmver}%{?snapver:-%{snapver}}
@@ -127,6 +127,7 @@ Patch158: 0001-Prevent-command-injection-via-rpmbuild-t.patch
Patch159: 0001-Extract-archiver-detection-out-of-doUncompress.patch
Patch160: 0002-Prevent-command-injection-via-rpmbuild-t-filename.patch
Patch161: 0003-Add-a-variable-argument-list-to-rpopen.patch
+Patch162: 0001-Fix-rpopen-rpclose-and-make-them-more-POSIXy.patch
# These are not yet upstream
Patch906: rpm-4.7.1-geode-i686.patch
@@ -679,6 +680,9 @@ fi
%doc doc/librpm/html/*
%changelog
+* Mon Nov 09 2026 Michal Domonkos <mdomonko@redhat.com> - 4.16.1.3-43
+- Fix rpopen()/rpclose() and make them more POSIXy (RHEL-288157)
+
* Mon Oct 26 2026 Michal Domonkos <mdomonko@redhat.com> - 4.16.1.3-42
- CVE-2026-84837: Prevent command injection via rpmbuild -t filename (RHEL-288157)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-13 18:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 18:33 [rpms/python3-rpm] epel9: Fix rpopen()/rpclose() and make them more POSIXy Michal Domonkos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox