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..5e992d417842aee70c4d3412f7a66ccf4f0f00d0 --- /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.c | 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 da70082d10a1a2022e3441141f97433daea1c953..b5be1a437ada040251bb12e31ac6d2a354b68a86 100644 --- a/rpm.spec +++ b/rpm.spec @@ -1,6 +1,6 @@ Name: rpm Version: 4.15.1 -Release: 61 +Release: 62 Summary: RPM Package Manager License: GPLv2+ URL: http://www.rpm.org/ @@ -228,6 +228,7 @@ Patch206: backport-Fix-division-by-zero-in-elfdeps-RhBug-2299414.patch Patch207: backport-Fix-memleak-when-process-policies.patch Patch208: backport-Enforce-the-same-sanity-checks-on-db-add-and-rebuild.patch Patch209: backport-Fix-a-memory-leak-on-rpmdb-importdb.patch +Patch210: backport-Return-1-from-fdSize-for-non-regular-files.patch BuildRequires: gcc autoconf automake libtool make gawk popt-devel openssl-devel readline-devel libdb-devel BuildRequires: zlib-devel libzstd-devel xz-devel bzip2-devel libarchive-devel ima-evm-utils-devel @@ -524,6 +525,9 @@ make check || (cat tests/rpmtests.log; exit 0) %{_mandir}/man1/gendiff.1* %changelog +* Fri Jul 18 2025 yanglongkang - 4.15.1-62 +- sync patches from upstream + * Thu Dec 5 2024 dongyuzhen - 4.15.1-61 - sync patches from upstream