From 16b0c0d901cf9f1b684170b17a9083c8f87f25a4 Mon Sep 17 00:00:00 2001 From: Andy Lau Date: Thu, 3 Jul 2025 02:04:18 +0000 Subject: [PATCH] sync patches from upstream (cherry picked from commit f7b3cd0f51625d096a997ac15f6ff0fcf8f5115c) --- ...-1-from-fdSize-for-non-regular-files.patch | 63 +++++++++++++++++++ rpm.spec | 6 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 backport-Return-1-from-fdSize-for-non-regular-files.patch diff --git a/backport-Return-1-from-fdSize-for-non-regular-files.patch b/backport-Return-1-from-fdSize-for-non-regular-files.patch new file mode 100644 index 0000000..2499d52 --- /dev/null +++ b/backport-Return-1-from-fdSize-for-non-regular-files.patch @@ -0,0 +1,63 @@ +From 063427c5f72e1cb50a61cb0973be127a00e93c2c Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Fri, 4 Apr 2025 16:59:41 +0200 +Subject: [PATCH] Return -1 from fdSize() for non-regular files + +I noticed that importing a key from a pipe did not work: + + $ cat /tmp/key | rpmkeys --import - + error: -: import read failed(0). + +While importing from a regular file on stdin worked: + + $ < /tmp/key rpmkeys --import - + +The cause was fdSize() returning 0 for a pipe descriptor. +rpmcliImportPubkeys() calls rpmioSlurp() which calls fdSize() like +this: + + size = fdSize(fd); + blen = (size >= 0 ? size : blenmax); + if (blen) { + /* read from the descriptor */ + } + +As a result, rpmioSlurp() concluded that the "file" was empty and +rpmcliImportPubkeys() reported an error: + + iorc = rpmioSlurp(fn, &buf, &blen); + if (iorc || buf == NULL || blen < 64) { + rpmlog(RPMLOG_ERR, _("%s: import read failed(%d).\n"), fn, iorc); + +This patch changes fdSize() to return an error for non-regular files. +This is in line with fstat(3) manual: + + st_size + This field gives the size of the file (if it is + a regular file or a symbolic link) in bytes. The size + of a symbolic link is the length of the pathname it + contains, without a terminating null byte. + +Returning an error on unsupported descriptors was pretty common before +commit 852398f8c6dcb4ad5ed0310e49e7d342a262be91 +("Lose unnecessary url type checking from fdSize()"). +--- + rpmio/rpmio.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c +index a0c7946..1665eee 100644 +--- a/rpmio/rpmio.c ++++ b/rpmio/rpmio.c +@@ -252,7 +252,7 @@ off_t fdSize(FD_t fd) + struct stat sb; + off_t rc = -1; + +- if (fd != NULL && fstat(Fileno(fd), &sb) == 0) ++ if (fd != NULL && fstat(Fileno(fd), &sb) == 0 && S_ISREG(sb.st_mode)) + rc = sb.st_size; + return rc; + } +-- +2.43.0 + diff --git a/rpm.spec b/rpm.spec index 238a84c..535bb12 100644 --- a/rpm.spec +++ b/rpm.spec @@ -1,6 +1,6 @@ Name: rpm Version: 4.18.2 -Release: 24 +Release: 25 Summary: RPM Package Manager License: GPL-2.0-or-later URL: https://rpm.org/ @@ -66,6 +66,7 @@ Patch6043: backport-Fix-FA_TOUCH-ed-files-getting-removed-on-failed-upda.patch Patch6044: backport-Fix-race-condition-in-rpmioMkpath.patch Patch6045: backport-Ignore-EPERM-for-root-when-setting-IMA-signature-xat.patch Patch6046: backport-Fix-a-copy-paste-help-description-of-rpmbuild-rf-and.patch +Patch6047: backport-Return-1-from-fdSize-for-non-regular-files.patch Patch9000: Add-digest-list-plugin.patch Patch9001: Add-IMA-digest-list-support.patch @@ -355,6 +356,9 @@ make clean %exclude %{_mandir}/man8/rpmspec.8* %changelog +* Wed Jul 2 2025 andy - 4.18.2-25 +- sync patches form upstream + * Mon Jun 16 2025 Linux_zhang - 4.18.2-24 - sync patches from upstream -- Gitee