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 0000000000000000000000000000000000000000..5752098bdfaf88f61be1d041f62e71bac364c1d6 --- /dev/null +++ b/backport-Return-1-from-fdSize-for-non-regular-files.patch @@ -0,0 +1,60 @@ +From 83867976fe7241ea2363f09230897c40248578d5 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.cc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c +index a03a616836..7537bc3267 100644 +--- a/rpmio/rpmio.c ++++ b/rpmio/rpmio.c +@@ -237,7 +237,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; + } diff --git a/rpm.spec b/rpm.spec index 67f288f65986d7a44daf9a38c04d856eee076cce..acb203d9879e77a80e4f4c79cb8fa9211b6e84ac 100644 --- a/rpm.spec +++ b/rpm.spec @@ -1,6 +1,6 @@ Name: rpm Version: 4.17.0 -Release: 46 +Release: 47 Summary: RPM Package Manager License: GPLv2+ URL: http://www.rpm.org/ @@ -131,6 +131,7 @@ Patch6099: backport-Fix-division-by-zero-in-elfdeps-RhBug-2299414.patch Patch6100: backport-Fix-memleak-when-process-policies.patch Patch6101: backport-Enforce-the-same-sanity-checks-on-db-add-and-rebuild.patch Patch6102: backport-Fix-a-memory-leak-on-rpmdb-importdb.patch +Patch6103: backport-Return-1-from-fdSize-for-non-regular-files.patch BuildRequires: gcc autoconf automake libtool make gawk popt-devel openssl-devel readline-devel BuildRequires: zlib-devel zstd-devel >= 1.3.8 xz-devel bzip2-devel libarchive-devel ima-evm-utils-devel @@ -421,6 +422,9 @@ make check || (cat tests/rpmtests.log; exit 0) %{_mandir}/man1/gendiff.1* %changelog +* Thu Jul 17 2025 yanglongkang - 4.17.0-47 +- sync patches from upstream + * Tue Nov 26 2024 hugel - 4.17.0-46 - sync patches from upstream