public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/python3-rpm] epel10: Fix rpopen()/rpclose() and make them more POSIXy
@ 2026-11-16 11:10 Michal Domonkos
  0 siblings, 0 replies; only message in thread
From: Michal Domonkos @ 2026-11-16 11:10 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : rpms/python3-rpm
            Branch : epel10
            Commit : 23e5ed659e37acb28eb00aafd4b1cc0096d5859b
            Author : Michal Domonkos <mdomonko@redhat.com>
            Date   : 2026-11-09T12:02:28+01:00
            Stats  : +158/-1 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/python3-rpm/c/23e5ed659e37acb28eb00aafd4b1cc0096d5859b?branch=epel10

            Log:
            Fix rpopen()/rpclose() and make them more POSIXy

Related: RHEL-288156

---
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..a4bb9a9
--- /dev/null
+++ b/0001-Fix-rpopen-rpclose-and-make-them-more-POSIXy.patch
@@ -0,0 +1,153 @@
+From 5fb7097ed422b894c6a4451edb4637260465ea38 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)
+---
+ tools/cliutils.c | 58 +++++++++++++++++++++++++++++-------------------
+ tools/cliutils.h |  2 +-
+ 2 files changed, 36 insertions(+), 24 deletions(-)
+
+diff --git a/tools/cliutils.c b/tools/cliutils.c
+index bf135ba40..c16f49f1c 100644
+--- a/tools/cliutils.c
++++ b/tools/cliutils.c
+@@ -11,6 +11,7 @@
+ #include "debug.h"
+ 
+ static pid_t pipeChild = 0;
++static pid_t rpopenChild = 0;
+ 
+ RPM_GNUC_NORETURN
+ void argerror(const char * desc)
+@@ -86,53 +87,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/tools/cliutils.h b/tools/cliutils.h
+index 4aee1ae72..600ccfa95 100644
+--- a/tools/cliutils.h
++++ b/tools/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 39c1874..a33ccf2 100644
--- a/rpm.spec
+++ b/rpm.spec
@@ -27,7 +27,7 @@
 
 %global rpmver 4.19.1.1
 #global snapver rc1
-%global baserelease 28
+%global baserelease 29
 %global sover 10
 
 %global srcver %{rpmver}%{?snapver:-%{snapver}}
@@ -192,6 +192,7 @@ rpm-4.19.x-improve-syslog.patch
 0003-Drop-leftover-filename-arg-from-doUncompress.patch
 0004-Rename-a-parameter-name-in-doUntar.patch
 0005-Prevent-shell-injection-via-RubyGem-filenames.patch
+0001-Fix-rpopen-rpclose-and-make-them-more-POSIXy.patch
 
 # These are not yet upstream
 rpm-4.7.1-geode-i686.patch
@@ -683,6 +684,9 @@ fi
 %doc %{_defaultdocdir}/rpm/API/
 
 %changelog
+* Mon Nov 09 2026 Michal Domonkos <mdomonko@redhat.com> - 4.19.1.1-29
+- Fix rpopen()/rpclose() and make them more POSIXy (RHEL-288156)
+
 * Wed Oct 21 2026 Michal Domonkos <mdomonko@redhat.com> - 4.19.1.1-28
 - CVE-2026-84233: Prevent macro injection via .gem filenames (RHEL-288155)
 - CVE-2026-84837: Prevent command injection via rpmbuild -t filename (RHEL-288156)

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-16 11:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 11:10 [rpms/python3-rpm] epel10: 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