[packages/cpio] Fix CVE-2026-66484 CVE-2026-66485 CVE-2026-66486; rel 2
arekm
arekm at pld-linux.org
Wed Aug 26 13:40:54 CEST 2026
commit 5ba52e28223bee392c9fd5c94d513ff359f2dd27
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Wed Aug 26 11:31:30 2026 +0200
Fix CVE-2026-66484 CVE-2026-66485 CVE-2026-66486; rel 2
cpio-CVE-2026-66484.patch | 25 +++
cpio-CVE-2026-66485.patch | 203 +++++++++++++++++++
cpio-CVE-2026-66486.patch | 451 +++++++++++++++++++++++++++++++++++++++++
cpio-c23.patch | 38 ++++
cpio-from_ascii-oob-read.patch | 26 +++
cpio-tar-name-overflow.patch | 44 ++++
cpio.spec | 25 ++-
7 files changed, 810 insertions(+), 2 deletions(-)
---
diff --git a/cpio.spec b/cpio.spec
index 3020bfc..d9f3080 100644
--- a/cpio.spec
+++ b/cpio.spec
@@ -1,3 +1,7 @@
+#
+# Conditional build:
+%bcond_without tests # unit tests
+#
Summary: GNU cpio archiving program
Summary(de.UTF-8): GNU-cpio-Archivierungsprogramm
Summary(es.UTF-8): Programa de empaquetado cpio de la GNU (usado por el utilitario rpm)
@@ -9,7 +13,7 @@ Summary(tr.UTF-8): GNU cpio arşivleme programı
Summary(uk.UTF-8): Архівна програма GNU
Name: cpio
Version: 2.15
-Release: 1
+Release: 2
License: GPL v3+
Group: Applications/Archiving
Source0: https://ftp.gnu.org/gnu/cpio/%{name}-%{version}.tar.bz2
@@ -18,6 +22,12 @@ Source1: http://www.mif.pg.gda.pl/homepages/ankry/man-PLD/%{name}-non-english-ma
# Source1-md5: 027552f4053477462a09fadc162a5e65
Patch0: %{name}-info.patch
Patch1: %{name}-ifdef.patch
+Patch2: %{name}-c23.patch
+Patch3: %{name}-CVE-2026-66484.patch
+Patch4: %{name}-CVE-2026-66485.patch
+Patch5: %{name}-CVE-2026-66486.patch
+Patch6: %{name}-from_ascii-oob-read.patch
+Patch7: %{name}-tar-name-overflow.patch
URL: http://www.gnu.org/software/cpio/
BuildRequires: autoconf >= 2.71
BuildRequires: automake >= 1:1.16.5
@@ -104,6 +114,12 @@ cpio копіює файли в або з архіву cpio або tar, який
%setup -q
%patch -P0 -p1
%patch -P1 -p1
+%patch -P2 -p1
+%patch -P3 -p1
+%patch -P4 -p1
+%patch -P5 -p1
+%patch -P6 -p1
+%patch -P7 -p1
%build
%{__gettextize}
@@ -116,11 +132,16 @@ cpio копіює файли в або з архіву cpio або tar, який
%{__make}
+%if %{with tests}
+%{__make} check
+%endif
+
%install
rm -rf $RPM_BUILD_ROOT
%{__make} install \
- DESTDIR=$RPM_BUILD_ROOT
+ DESTDIR=$RPM_BUILD_ROOT \
+ AM_UPDATE_INFO_DIR=no
bzip2 -dc %{SOURCE1} | tar xf - -C $RPM_BUILD_ROOT%{_mandir}
%{__rm} $RPM_BUILD_ROOT%{_mandir}/README.cpio-non-english-man-pages
diff --git a/cpio-CVE-2026-66484.patch b/cpio-CVE-2026-66484.patch
new file mode 100644
index 0000000..56eb197
--- /dev/null
+++ b/cpio-CVE-2026-66484.patch
@@ -0,0 +1,25 @@
+From e2b9cbdd3354d2b1569b7390d1bc15c1930559ad Mon Sep 17 00:00:00 2001
+From: Sergey Poznyakoff <gray at gnu.org>
+Date: Thu, 23 Jul 2026 15:55:46 +0300
+Subject: [PATCH] The --no-absolute-filenames option affects hard link targets
+ too.
+
+CVE-2026-66484: in copy-in mode the tar hard link target was passed to
+link_to_name() unsanitized, so an archive could link outside the destination
+directory even with --no-absolute-filenames.
+
+https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=e2b9cbdd3354d2b1569b7390d1bc15c1930559ad
+
+* src/tar.c (stash_tar_linkname): Apply cpio_safer_name_suffix.
+---
+--- a/src/tar.c
++++ b/src/tar.c
+@@ -37,6 +37,8 @@
+
+ strncpy (hold_tar_linkname, linkname, TARLINKNAMESIZE);
+ hold_tar_linkname[TARLINKNAMESIZE] = '\0';
++ cpio_safer_name_suffix (hold_tar_linkname, true, !no_abs_paths_flag,
++ false);
+ return hold_tar_linkname;
+ }
+
diff --git a/cpio-CVE-2026-66485.patch b/cpio-CVE-2026-66485.patch
new file mode 100644
index 0000000..28bcdbf
--- /dev/null
+++ b/cpio-CVE-2026-66485.patch
@@ -0,0 +1,203 @@
+From 3cd514031371d8aeeaf2048aa10103e02831aaa9 Mon Sep 17 00:00:00 2001
+From: Sergey Poznyakoff <gray at gnu.org>
+Date: Fri, 1 May 2026 08:19:41 +0300
+Subject: [PATCH] Minor fixes
+
+CVE-2026-66485: make_path() sized an alloca() from the archive-controlled
+path name, so a long enough nested member name overflowed the stack.
+
+https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=3cd514031371d8aeeaf2048aa10103e02831aaa9
+
+* src/makepath.c: Don't use alloca.
+* src/userspec.c: Likewise.
+---
+--- a/src/makepath.c
++++ b/src/makepath.c
+@@ -47,24 +47,19 @@
+ Return 0 if ARGPATH exists as a directory with the proper
+ ownership and permissions when done, otherwise 1. */
+
+-int
+-make_path (char const *argpath,
+- uid_t owner,
+- gid_t group,
+- const char *verbose_fmt_string)
++static int
++make_path0 (char *dirpath,
++ uid_t owner,
++ gid_t group,
++ const char *verbose_fmt_string)
+ {
+- char *dirpath; /* A copy we can scribble NULs on. */
+ struct stat stats;
+- int retval = 0;
+ mode_t tmpmode;
+ mode_t invert_permissions;
+ int we_are_root = getuid () == 0;
+- dirpath = alloca (strlen (argpath) + 1);
+-
+- strcpy (dirpath, argpath);
+
+ if (stat (dirpath, &stats))
+- {
++ {
+ tmpmode = MODE_RWX & ~ newdir_umask;
+ invert_permissions = we_are_root ? 0 : MODE_WXUSR & ~ tmpmode;
+
+@@ -157,5 +152,19 @@
+
+ }
+
++ return 0;
++}
++
++int
++make_path (char const *argpath,
++ uid_t owner,
++ gid_t group,
++ const char *verbose_fmt_string)
++{
++ char *dirpath = xstrdup (argpath);
++ int retval = make_path0 (dirpath, owner, group, verbose_fmt_string);
++ free (dirpath);
+ return retval;
+ }
++
++
+--- a/src/userspec.c
++++ b/src/userspec.c
+@@ -19,7 +19,6 @@
+ /* Written by David MacKenzie <djm at gnu.ai.mit.edu>. */
+
+ #include <system.h>
+-#include <alloca.h>
+ #include <stdio.h>
+ #include <ctype.h>
+ #include <sys/types.h>
+@@ -33,18 +32,6 @@
+ # define endgrent()
+ #endif
+
+-/* Perform the equivalent of the statement `dest = strdup (src);',
+- but obtaining storage via alloca instead of from the heap. */
+-
+-#define V_STRDUP(dest, src) \
+- do \
+- { \
+- int _len = strlen ((src)); \
+- (dest) = (char *) alloca (_len + 1); \
+- strcpy (dest, src); \
+- } \
+- while (0)
+-
+ /* Return nonzero if STR represents an unsigned decimal integer,
+ otherwise return 0. */
+
+@@ -57,6 +44,18 @@
+ return 1;
+ }
+
++static void
++store_string (char **bufptr, size_t *buflen, char *str)
++{
++ size_t len = strlen (str) + 1;
++ if (len > *buflen)
++ {
++ *bufptr = xrealloc (*bufptr, len);
++ *buflen = len;
++ }
++ strcpy (*bufptr, str);
++}
++
+ /* Extract from NAME, which has the form "[user][:.][group]",
+ a USERNAME, UID U, GROUPNAME, and GID G.
+ Either user or group, or both, must be present.
+@@ -70,23 +69,21 @@
+ Return NULL if successful, a static error message string if not. */
+
+ const char *
+-parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
+- char **username_arg, char **groupname_arg)
++parse_user_spec0 (char *spec, uid_t *uid, gid_t *gid,
++ char **username_arg, char **groupname_arg)
+ {
+ static const char *tired = "virtual memory exhausted";
+ const char *error_msg;
+- char *spec; /* A copy we can write on. */
+ struct passwd *pwd;
+ struct group *grp;
+ char *g, *u, *separator;
+- char *groupname;
++ char *groupname = NULL;
++ size_t grouplen = 0;
+
+ error_msg = NULL;
+ *username_arg = *groupname_arg = NULL;
+ groupname = NULL;
+
+- V_STRDUP (spec, spec_arg);
+-
+ /* Find the separator if there is one. */
+ separator = strchr (spec, ':');
+ if (separator == NULL)
+@@ -143,11 +140,12 @@
+ if (grp == NULL)
+ {
+ char nbuf[UINTMAX_STRSIZE_BOUND];
+- V_STRDUP (groupname, umaxtostr (pwd->pw_gid, nbuf));
++ store_string (&groupname, &grouplen,
++ umaxtostr (pwd->pw_gid, nbuf));
+ }
+ else
+ {
+- V_STRDUP (groupname, grp->gr_name);
++ store_string (&groupname, &grouplen, grp->gr_name);
+ }
+ endgrent ();
+ }
+@@ -178,7 +176,7 @@
+ endgrent (); /* Save a file descriptor. */
+
+ if (error_msg == NULL)
+- V_STRDUP (groupname, g);
++ store_string (&groupname, &grouplen, g);
+ }
+
+ if (error_msg == NULL)
+@@ -191,23 +189,24 @@
+ }
+
+ if (groupname != NULL && error_msg == NULL)
+- {
+- *groupname_arg = strdup (groupname);
+- if (*groupname_arg == NULL)
+- {
+- if (*username_arg != NULL)
+- {
+- free (*username_arg);
+- *username_arg = NULL;
+- }
+- error_msg = tired;
+- }
+- }
++ *groupname_arg = groupname;
+ }
++ else
++ free (groupname);
+
+ return error_msg;
+ }
+
++const char *
++parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid,
++ char **username, char **groupname)
++{
++ char *spec = xstrdup (spec_arg);
++ const char *retval = parse_user_spec0 (spec, uid, gid, username, groupname);
++ free (spec);
++ return retval;
++}
++
+ #ifdef TEST
+
+ #define NULL_CHECK(s) ((s) == NULL ? "(null)" : (s))
diff --git a/cpio-CVE-2026-66486.patch b/cpio-CVE-2026-66486.patch
new file mode 100644
index 0000000..42ef8ed
--- /dev/null
+++ b/cpio-CVE-2026-66486.patch
@@ -0,0 +1,451 @@
+From 2ff9600c9ef32e88759843cdbde74c8db5ae9b30 Mon Sep 17 00:00:00 2001
+From: Sergey Poznyakoff <gray at gnu.org>
+Date: Thu, 23 Jul 2026 17:26:05 +0300
+Subject: [PATCH] Quote file names in error messages and in listings.
+
+CVE-2026-66486: member names printed by "cpio -it" were not escaped, so an
+archive could inject terminal control sequences into the listing.
+
+https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=2ff9600c9ef32e88759843cdbde74c8db5ae9b30
+
+* doc/cpio.texi: Document changes.
+* src/copyin.c: Quote file and member names.
+* src/copyout.c: Likewise.
+* src/copypass.c: Likewise.
+* src/main.c: New options: --quoting-style and --quote-chars.
+(process_args): Set default quoting style.
+* tests/CVE-2019-14866.at: Fix expected output.
+
+Backported to 2.15: NEWS hunk dropped, the two new helpers in main.c
+re-anchored (2.15 has no get_block_size()).
+---
+--- a/doc/cpio.texi
++++ b/doc/cpio.texi
+@@ -814,6 +814,19 @@
+ [@ref{copy-in}, at ref{copy-out}, at ref{copy-pass}]
+ @*Do not print the number of blocks copied.
+
++ at item --quote-chars=@var{string}
++Always quote characters from @var{string}, even if the selected
++quoting style would not quote them (@pxref{quoting styles,,,tar,GNU
++tar}).
++
++ at item --quoting-style=@var{style}
++Set quoting style to use when printing member and file names
++(@pxref{quoting styles,,,tar,GNU tar}). Valid @var{style} values are:
++ at code{literal}, @code{shell}, @code{shell-always}, @code{c},
++ at code{escape}, @code{locale}, and @code{clocale}. Default quoting
++style is @code{literal}, unless overridden while configuring the
++package.
++
+ @item -r
+ @itemx --rename
+ [@ref{copy-in}]
+--- a/src/copyin.c
++++ b/src/copyin.c
+@@ -114,7 +114,7 @@
+ if (file_hdr->c_filesize < 0 || file_hdr->c_filesize > SIZE_MAX-1)
+ {
+ error (0, 0, _("%s: stored filename length is out of range"),
+- file_hdr->c_name);
++ quote (file_hdr->c_name));
+ link_name = NULL;
+ }
+ else
+@@ -150,7 +150,11 @@
+ }
+ else
+ #endif
+- long_format (file_hdr, (char *) 0);
++ long_format (file_hdr, NULL);
++ }
++ else if (name_end == '\n' && isatty (fileno (stdout)))
++ {
++ printf ("%s%c", quotearg (file_hdr->c_name), name_end);
+ }
+ else
+ {
+@@ -173,7 +177,7 @@
+ if (crc != file_hdr->c_chksum)
+ {
+ error (0, 0, _("%s: checksum error (0x%x, should be 0x%x)"),
+- file_hdr->c_name, crc, file_hdr->c_chksum);
++ quote (file_hdr->c_name), crc, file_hdr->c_chksum);
+ }
+ }
+ }
+@@ -200,7 +204,7 @@
+ && file_hdr->c_mtime <= file_stat.st_mtime)
+ {
+ error (0, 0, _("%s not created: newer or same age version exists"),
+- file_hdr->c_name);
++ quote (file_hdr->c_name));
+ tape_toss_input (in_file_des, file_hdr->c_filesize);
+ tape_skip_padding (in_file_des, file_hdr->c_filesize);
+ return -1; /* Go to the next file. */
+@@ -210,7 +214,7 @@
+ : unlink (file_hdr->c_name))
+ {
+ error (0, errno, _("cannot remove current %s"),
+- file_hdr->c_name);
++ quote (file_hdr->c_name));
+ tape_toss_input (in_file_des, file_hdr->c_filesize);
+ tape_skip_padding (in_file_des, file_hdr->c_filesize);
+ return -1; /* Go to the next file. */
+@@ -271,7 +275,8 @@
+ if (link_res < 0)
+ {
+ error (0, errno, _("cannot link %s to %s"),
+- d->header.c_name, file_hdr->c_name);
++ quote_n (0, d->header.c_name),
++ quote_n (1, file_hdr->c_name));
+ }
+ if (d_prev != NULL)
+ d_prev->next = d->next;
+@@ -467,7 +472,8 @@
+ if (link_res < 0)
+ {
+ error (0, errno, _("cannot link %s to %s"),
+- file_hdr->c_tar_linkname, file_hdr->c_name);
++ quote_n (0, file_hdr->c_tar_linkname),
++ quote_n (1, file_hdr->c_name));
+ }
+ return;
+ }
+@@ -500,7 +506,7 @@
+ swapping_halfwords = true;
+ else
+ error (0, 0, _("cannot swap halfwords of %s: odd number of halfwords"),
+- file_hdr->c_name);
++ quote (file_hdr->c_name));
+ }
+ if (swap_bytes_flag)
+ {
+@@ -508,7 +514,7 @@
+ swapping_bytes = true;
+ else
+ error (0, 0, _("cannot swap bytes of %s: odd number of bytes"),
+- file_hdr->c_name);
++ quote (file_hdr->c_name));
+ }
+ copy_files_tape_to_disk (in_file_des, out_file_des, file_hdr->c_filesize);
+ disk_empty_output_buffer (out_file_des, true);
+@@ -519,7 +525,7 @@
+ {
+ if (crc != file_hdr->c_chksum)
+ error (0, 0, _("%s: checksum error (0x%x, should be 0x%x)"),
+- file_hdr->c_name, crc, file_hdr->c_chksum);
++ quote (file_hdr->c_name), crc, file_hdr->c_chksum);
+ }
+ tape_skip_padding (in_file_des, file_hdr->c_filesize);
+ return;
+@@ -534,7 +540,7 @@
+ {
+ if (crc != file_hdr->c_chksum)
+ error (0, 0, _("%s: checksum error (0x%x, should be 0x%x)"),
+- file_hdr->c_name, crc, file_hdr->c_chksum);
++ quote (file_hdr->c_name), crc, file_hdr->c_chksum);
+ }
+
+ tape_skip_padding (in_file_des, file_hdr->c_filesize);
+@@ -582,7 +588,8 @@
+ if (link_res < 0)
+ {
+ error (0, errno, _("cannot link %s to %s"),
+- file_hdr->c_tar_linkname, file_hdr->c_name);
++ quote_n (0, file_hdr->c_tar_linkname),
++ quote_n (1, file_hdr->c_name));
+ /* Something must be wrong, because we couldn't
+ find the file to link to. But can we assume
+ that the device maj/min numbers are correct
+@@ -855,7 +862,7 @@
+ #endif
+
+ default:
+- error (0, 0, _("%s: unknown file type"), file_hdr->c_name);
++ error (0, 0, _("%s: unknown file type"), quote (file_hdr->c_name));
+ tape_toss_input (in_file_des, file_hdr->c_filesize);
+ tape_skip_padding (in_file_des, file_hdr->c_filesize);
+ }
+@@ -1550,13 +1557,13 @@
+ if (crc != file_hdr.c_chksum)
+ {
+ error (0, 0, _("%s: checksum error (0x%x, should be 0x%x)"),
+- file_hdr.c_name, crc, file_hdr.c_chksum);
++ quote (file_hdr.c_name), crc, file_hdr.c_chksum);
+ }
+ /* Debian hack: -v and -V now work with --only-verify-crc.
+ (99/11/10) -BEM */
+ if (verbose_flag)
+ {
+- fprintf (stderr, "%s\n", file_hdr.c_name);
++ fprintf (stderr, "%s\n", quotearg (file_hdr.c_name));
+ }
+ if (dot_flag)
+ {
+@@ -1581,7 +1588,7 @@
+ copyin_file(&file_hdr, in_file_des);
+
+ if (verbose_flag)
+- fprintf (stderr, "%s\n", file_hdr.c_name);
++ fprintf (stderr, "%s\n", quotearg (file_hdr.c_name));
+ if (dot_flag)
+ fputc ('.', stderr);
+ }
+--- a/src/copyout.c
++++ b/src/copyout.c
+@@ -46,7 +46,8 @@
+ {
+ bytes_read = read (in_file_des, buf, BUFSIZ);
+ if (bytes_read < 0)
+- error (PAXEXIT_FAILURE, errno, _("cannot read checksum for %s"), file_name);
++ error (PAXEXIT_FAILURE, errno, _("cannot read checksum for %s"),
++ quote (file_name));
+ if (bytes_read == 0)
+ break;
+ for (i = 0; i < bytes_read; i++)
+@@ -54,7 +55,8 @@
+ file_size -= bytes_read;
+ }
+ if (lseek (in_file_des, 0L, SEEK_SET))
+- error (PAXEXIT_FAILURE, errno, _("cannot read checksum for %s"), file_name);
++ error (PAXEXIT_FAILURE, errno, _("cannot read checksum for %s"),
++ quote (file_name));
+
+ return crc;
+ }
+@@ -288,7 +290,7 @@
+ char valbuf[UINTMAX_STRSIZE_BOUND + 1];
+ char maxbuf[UINTMAX_STRSIZE_BOUND + 1];
+ error (0, 0, _("%s: value %s %s out of allowed range 0..%s"),
+- filename, fieldname,
++ quote (filename), fieldname,
+ STRINGIFY_BIGINT (value, valbuf),
+ STRINGIFY_BIGINT (MAX_VAL_WITH_DIGITS (width - nul, LG_8),
+ maxbuf));
+@@ -298,7 +300,7 @@
+ field_width_warning (const char *filename, const char *fieldname)
+ {
+ if (warn_option & CPIO_WARN_TRUNCATE)
+- error (0, 0, _("%s: truncating %s"), filename, fieldname);
++ error (0, 0, _("%s: truncating %s"), quote (filename), fieldname);
+ }
+
+ void
+@@ -466,7 +468,7 @@
+ short_hdr.c_dev = makedev (file_hdr->c_dev_maj, file_hdr->c_dev_min);
+
+ if ((warn_option & CPIO_WARN_TRUNCATE) && (file_hdr->c_ino >> 16) != 0)
+- error (0, 0, _("%s: truncating inode number"), file_hdr->c_name);
++ error (0, 0, _("%s: truncating inode number"), quote (file_hdr->c_name));
+
+ short_hdr.c_ino = file_hdr->c_ino & 0xFFFF;
+ if (short_hdr.c_ino != file_hdr->c_ino)
+@@ -497,7 +499,7 @@
+ {
+ char maxbuf[UINTMAX_STRSIZE_BOUND + 1];
+ error (0, 0, _("%s: value %s %s out of allowed range 0..%u"),
+- file_hdr->c_name, _("name size"),
++ quote (file_hdr->c_name), _("name size"),
+ STRINGIFY_BIGINT (file_hdr->c_namesize, maxbuf), 0xFFFFu);
+ return 1;
+ }
+@@ -510,7 +512,7 @@
+ {
+ char maxbuf[UINTMAX_STRSIZE_BOUND + 1];
+ error (0, 0, _("%s: value %s %s out of allowed range 0..%lu"),
+- file_hdr->c_name, _("file size"),
++ quote (file_hdr->c_name), _("file size"),
+ STRINGIFY_BIGINT (file_hdr->c_namesize, maxbuf), 0xFFFFFFFFlu);
+ return 1;
+ }
+@@ -558,7 +560,7 @@
+ case arf_ustar:
+ if (is_tar_filename_too_long (file_hdr->c_name))
+ {
+- error (0, 0, _("%s: file name too long"), file_hdr->c_name);
++ error (0, 0, _("%s: file name too long"), quote (file_hdr->c_name));
+ return 1;
+ }
+ return write_out_tar_header (file_hdr, out_des);
+@@ -749,7 +751,7 @@
+ if (archive_format == arf_tar)
+ {
+ error (0, 0, _("%s not dumped: not a regular file"),
+- orig_file_name);
++ quote (orig_file_name));
+ continue;
+ }
+ else if (archive_format == arf_ustar)
+@@ -800,7 +802,7 @@
+ if (link_size + 1 > 100)
+ {
+ error (0, 0, _("%s: symbolic link too long"),
+- file_hdr.c_name);
++ quote (file_hdr.c_name));
+ }
+ else
+ {
+@@ -823,11 +825,11 @@
+ #endif
+
+ default:
+- error (0, 0, _("%s: unknown file type"), orig_file_name);
++ error (0, 0, _("%s: unknown file type"), quote (orig_file_name));
+ }
+
+ if (verbose_flag)
+- fprintf (stderr, "%s\n", orig_file_name);
++ fprintf (stderr, "%s\n", quote (orig_file_name));
+ if (dot_flag)
+ fputc ('.', stderr);
+ }
+--- a/src/copypass.c
++++ b/src/copypass.c
+@@ -127,7 +127,7 @@
+ && in_file_stat.st_mtime <= out_file_stat.st_mtime)
+ {
+ error (0, 0, _("%s not created: newer or same age version exists"),
+- output_name.ds_string);
++ quote (output_name.ds_string));
+ continue; /* Go to the next file. */
+ }
+ else if (S_ISDIR (out_file_stat.st_mode)
+@@ -135,7 +135,7 @@
+ : unlink (output_name.ds_string))
+ {
+ error (0, errno, _("cannot remove current %s"),
+- output_name.ds_string);
++ quote (output_name.ds_string));
+ continue; /* Go to the next file. */
+ }
+ }
+@@ -312,7 +312,8 @@
+ #endif
+ else
+ {
+- error (0, 0, _("%s: unknown file type"), input_name.ds_string);
++ error (0, 0, _("%s: unknown file type"),
++ quote (input_name.ds_string));
+ }
+
+ if (verbose_flag)
+@@ -388,12 +389,12 @@
+ {
+ if (verbose_flag)
+ error (0, 0, _("%s linked to %s"),
+- link_target, link_name);
++ quote_n (0, link_target), quote_n (1, link_name));
+ }
+ else if (link_flag)
+ {
+ error (0, errno, _("cannot link %s to %s"),
+- link_target, link_name);
++ quote_n (0, link_target), quote_n (1, link_name));
+ }
+ return res;
+ }
+--- a/src/main.c
++++ b/src/main.c
+@@ -61,7 +61,9 @@
+ RENUMBER_INODES_OPTION,
+ IGNORE_DEVNO_OPTION,
+ IGNORE_DIRNLINK_OPTION,
+- DEVICE_INDEPENDENT_OPTION
++ DEVICE_INDEPENDENT_OPTION,
++ QUOTING_STYLE_OPTION,
++ QUOTE_CHARS_OPTION
+ };
+
+ const char *program_authors[] =
+@@ -141,6 +143,12 @@
+ N_("Control warning display. Currently FLAG is one of 'none', 'truncate', 'all'. Multiple options accumulate."), GRID+1 },
+ {"owner", 'R', N_("[USER][:.][GROUP]"), 0,
+ N_("Set the ownership of all files created to the specified USER and/or GROUP"), GRID+1 },
++ {"quoting-style", QUOTING_STYLE_OPTION, N_("STYLE"), 0,
++ N_("set name quoting style; use --quoting-style=help for a list of valid STYLE values"),
++ GRID+1 },
++ {"quote-chars", QUOTE_CHARS_OPTION, N_("STRING"), 0,
++ N_("additionally quote characters from STRING"),
++ GRID+1 },
+ #undef GRID
+
+ #define GRID 110
+@@ -295,6 +303,36 @@
+ return 1;
+ }
+
++static void
++cpio_list_quoting_styles (int indent)
++{
++ int i;
++
++ for (i = 0; quoting_style_args[i]; i++)
++ printf ("%*.*s%s\n", indent, indent, "", quoting_style_args[i]);
++}
++
++static void
++cpio_set_quoting_style (char *arg)
++{
++ if (strcmp (arg, "help") == 0)
++ {
++ cpio_list_quoting_styles (0);
++ exit (EXIT_SUCCESS);
++ }
++
++ for (idx_t i = 0; quoting_style_args[i]; i++)
++ if (strcmp (arg, quoting_style_args[i]) == 0)
++ {
++ set_quoting_style (NULL, i);
++ return;
++ }
++ USAGE_ERROR ((0, 0,
++ _("Unknown quoting style '%s'."
++ " Try '%s --quoting-style=help' to get a list."),
++ arg, program_name));
++}
++
+ static error_t
+ parse_opt (int key, char *arg, struct argp_state *state)
+ {
+@@ -454,10 +492,19 @@
+ copy_function = process_copy_pass;
+ break;
+
++ case QUOTE_CHARS_OPTION:
++ for (;*arg; arg++)
++ set_char_quoting (NULL, *arg, 1);
++ break;
++
++ case QUOTING_STYLE_OPTION:
++ cpio_set_quoting_style (arg);
++ break;
++
+ case IGNORE_DEVNO_OPTION:
+ ignore_devno_option = 1;
+ break;
+-
++
+ case RENUMBER_INODES_OPTION:
+ renumber_inodes_option = 1;
+ break;
+@@ -593,6 +640,8 @@
+
+ xstat = lstat;
+
++ set_quoting_style (NULL, DEFAULT_QUOTING_STYLE);
++
+ if (argp_parse (&argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
+ exit (PAXEXIT_FAILURE);
+
+--- a/tests/CVE-2019-14866.at
++++ b/tests/CVE-2019-14866.at
+@@ -29,7 +29,7 @@
+ ],
+ [0],
+ [],
+-[cpio: file: value size 17179869184 out of allowed range 0..8589934591
++[cpio: 'file': value size 17179869184 out of allowed range 0..8589934591
+ 2 blocks
+ ])
+ AT_CLEANUP
diff --git a/cpio-c23.patch b/cpio-c23.patch
new file mode 100644
index 0000000..99882db
--- /dev/null
+++ b/cpio-c23.patch
@@ -0,0 +1,38 @@
+From f42137f5ab9cf07d1e62edc05e0212688d3ebaa2 Mon Sep 17 00:00:00 2001
+From: Sergey Poznyakoff <gray at gnu.org>
+Date: Tue, 6 May 2025 21:02:43 +0300
+Subject: [PATCH] Fix c23 conformity
+
+GCC 15 defaults to C23, where an empty parameter list means (void), so every
+call through the xstat and copy_function pointers is rejected.
+
+https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=f42137f5ab9cf07d1e62edc05e0212688d3ebaa2
+---
+--- a/src/extern.h
++++ b/src/extern.h
+@@ -97,8 +97,8 @@
+ extern char output_is_special;
+ extern char input_is_seekable;
+ extern char output_is_seekable;
+-extern int (*xstat) ();
+-extern void (*copy_function) ();
++extern int (*xstat) (const char *, struct stat *);
++extern void (*copy_function) (void);
+ extern char *change_directory_option;
+
+ #define STRINGIFY_BIGINT(i, b) umaxtostr (i, b)
+--- a/src/global.c
++++ b/src/global.c
+@@ -185,10 +185,10 @@
+
+ /* A pointer to either lstat or stat, depending on whether
+ dereferencing of symlinks is done for input files. */
+-int (*xstat) ();
++int (*xstat) (const char *, struct stat *);
+
+ /* Which copy operation to perform. (-i, -o, -p) */
+-void (*copy_function) () = 0;
++void (*copy_function) (void) = 0;
+
+ char *change_directory_option;
+
diff --git a/cpio-from_ascii-oob-read.patch b/cpio-from_ascii-oob-read.patch
new file mode 100644
index 0000000..305939c
--- /dev/null
+++ b/cpio-from_ascii-oob-read.patch
@@ -0,0 +1,26 @@
+From bf16382570ace03c1d4c5413a558f195f680e7f6 Mon Sep 17 00:00:00 2001
+From: Sergey Poznyakoff <gray at gnu.org>
+Date: Thu, 29 May 2025 08:28:33 +0300
+Subject: [PATCH] Fix invalid memory access
+
+from_ascii() dereferenced the header field before testing for its end, so an
+all-blank archive-controlled field read one byte past the buffer.
+
+https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=bf16382570ace03c1d4c5413a558f195f680e7f6
+---
+--- a/src/copyin.c
++++ b/src/copyin.c
+@@ -1004,11 +1004,8 @@
+ int overflow = 0;
+ static char codetab[] = "0123456789ABCDEF";
+
+- for (; *buf == ' '; buf++)
+- {
+- if (buf == end)
+- return 0;
+- }
++ for (; buf < end && *buf == ' '; buf++)
++ ;
+
+ if (buf == end || *buf == 0)
+ return 0;
diff --git a/cpio-tar-name-overflow.patch b/cpio-tar-name-overflow.patch
new file mode 100644
index 0000000..f5ad7b9
--- /dev/null
+++ b/cpio-tar-name-overflow.patch
@@ -0,0 +1,44 @@
+From e8931bebb9e159a67db64ac1ac86314566ad24d8 Mon Sep 17 00:00:00 2001
+From: Sergey Poznyakoff <gray at gnu.org>
+Date: Sat, 25 Jul 2026 09:23:10 +0300
+Subject: [PATCH] Fix possible stack overflow in write_out_tar_header
+
+A user or group name longer than the 32-byte tar header field was copied with
+strcpy(), overrunning the header buffer.
+
+Squash of the fix and its follow-up off-by-one correction:
+https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=e8931bebb9e159a67db64ac1ac86314566ad24d8
+https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=b5c7d6ee27520c3bf94fe29b3ceed86421759cb0
+
+* src/tar.c (tarnamecpy): New function.
+(write_out_tar_header): Use it for uname and gname.
+---
+--- a/src/tar.c
++++ b/src/tar.c
+@@ -128,6 +128,13 @@
+ } \
+ while (0)
+
++static void
++tarnamecpy (char *buf, char const *name, size_t size)
++{
++ strncpy (buf, name, size-1);
++ buf[size-1] = 0;
++}
++
+ /* Write out header FILE_HDR, including the file name, to file
+ descriptor OUT_DES. */
+
+@@ -216,10 +223,10 @@
+
+ name = getuser (file_hdr->c_uid);
+ if (name)
+- strcpy (tar_hdr->uname, name);
++ tarnamecpy (tar_hdr->uname, name, sizeof (tar_hdr->uname));
+ name = getgroup (file_hdr->c_gid);
+ if (name)
+- strcpy (tar_hdr->gname, name);
++ tarnamecpy (tar_hdr->gname, name, sizeof (tar_hdr->gname));
+
+ TO_OCT (file_hdr, c_rdev_maj, 8, tar_hdr, devmajor);
+ TO_OCT (file_hdr, c_rdev_min, 8, tar_hdr, devminor);
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/cpio.git/commitdiff/5ba52e28223bee392c9fd5c94d513ff359f2dd27
More information about the pld-cvs-commit
mailing list