Description: Fix CVE-2026-66484: hard link target escapes with --no-absolute-filenames
 Apply cpio_safer_name_suffix to tar hard link targets (upstream e2b9cbdd),
 but leave symbolic link targets intact (upstream follow-up b19a03e4; without
 it e2b9cbdd reintroduces the symlink breakage reverted for CVE-2023-7207).
Origin: upstream, https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=e2b9cbdd3354d2b1569b7390d1bc15c1930559ad https://git.savannah.gnu.org/cgit/cpio.git/commit/?id=b19a03e4c0752884c40a3fb58f61d61de8d5ab9e
Bug-Debian: https://bugs.debian.org/1144387
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2026-66484
Forwarded: not-needed
Last-Update: 2026-10-31
---
diff --git a/src/tar.c b/src/tar.c
index 493f299..a1fc60a 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -36,6 +36,8 @@ stash_tar_linkname (char *linkname)
 
   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/src/tar.c b/src/tar.c
index c85336d..9ef5184 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -30,14 +30,19 @@
 /* Stash the tar linkname in static storage.  */
 
 static char *
-stash_tar_linkname (char *linkname)
+stash_tar_linkname (char *linkname, bool symlink_target)
 {
   static char hold_tar_linkname[TARLINKNAMESIZE + 1];
 
   strncpy (hold_tar_linkname, linkname, TARLINKNAMESIZE);
   hold_tar_linkname[TARLINKNAMESIZE] = '\0';
-  cpio_safer_name_suffix (hold_tar_linkname, true, !no_abs_paths_flag,
-  			  false);
+  /* A hard link target names another member of the same archive, so it
+     is subject to --no-absolute-filenames.  A symbolic link target is
+     stored verbatim and resolved only when the link is followed;
+     rewriting it would silently make the link point elsewhere.  */
+  if (!symlink_target)
+    cpio_safer_name_suffix (hold_tar_linkname, true, !no_abs_paths_flag,
+			    false);
   return hold_tar_linkname;
 }
 
@@ -383,7 +388,7 @@ read_in_tar_header (struct cpio_file_stat *file_hdr, int in_des)
 	     be broken, and for device files with multiple links it
 	     puts the name of the link into linkname, but leaves typeflag
 	     as CHRTYPE, BLKTYPE, FIFOTYPE, etc.  */
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
+	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname, false);
 
 	  /* Does POSIX say that the filesize must be 0 for devices?  We
 	     assume so, but HPUX's POSIX tar sets it to be 1 which causes
@@ -395,27 +400,27 @@ read_in_tar_header (struct cpio_file_stat *file_hdr, int in_des)
 	  break;
 	case BLKTYPE:
 	  file_hdr->c_mode |= CP_IFBLK;
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
+	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname, false);
 	  file_hdr->c_filesize = 0;
 	  break;
 #ifdef CP_IFIFO
 	case FIFOTYPE:
 	  file_hdr->c_mode |= CP_IFIFO;
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
+	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname, false);
 	  file_hdr->c_filesize = 0;
 	  break;
 #endif
 	case SYMTYPE:
 #ifdef CP_IFLNK
 	  file_hdr->c_mode |= CP_IFLNK;
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
+	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname, true);
 	  file_hdr->c_filesize = 0;
 	  break;
 	  /* Else fall through.  */
 #endif
 	case LNKTYPE:
 	  file_hdr->c_mode |= CP_IFREG;
-	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname);
+	  file_hdr->c_tar_linkname = stash_tar_linkname (tar_hdr->linkname, false);
 	  file_hdr->c_filesize = 0;
 	  break;
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 83ddc23..e5096e5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,7 +57,8 @@ TESTSUITE_AT = \
  CVE-2015-1197.at\
  CVE-2019-14866.at\
  linktime.at\
- linktime01.at
+ linktime01.at\
+ symlink-tar-abs.at
 
 TESTSUITE = $(srcdir)/testsuite
 
diff --git a/tests/symlink-tar-abs.at b/tests/symlink-tar-abs.at
new file mode 100644
index 0000000..9d4f9a2
--- /dev/null
+++ b/tests/symlink-tar-abs.at
@@ -0,0 +1,54 @@
+# Process this file with autom4te to create testsuite.  -*- Autotest -*-
+# Copyright (C) 2026 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# --no-absolute-filenames must not rewrite symbolic link targets.  A
+# symlink target is stored verbatim and is resolved only when the link
+# is followed, so stripping a leading `/' or `../' from it silently
+# makes the link point somewhere else.  Hard link targets, which name
+# another member of the same archive, are still stripped.
+
+AT_SETUP([--no-absolute-filenames keeps symlink targets (tar format)])
+AT_KEYWORDS([symlink-tar-abs])
+
+AT_CHECK([
+file --help >/dev/null 2>&1 || AT_SKIP_TEST
+
+AT_DATA([filelist],
+[abslink
+dotdotlink
+])
+
+mkdir dir
+cd dir
+
+ln -s /absolute/file/name abslink
+ln -s ../relative/file/name dotdotlink
+cpio -o -H ustar < ../filelist > ../test.tar
+
+cd ..
+
+mkdir out
+cd out
+cpio -i --no-absolute-filenames < ../test.tar
+file -h abslink dotdotlink | sed -n 's/:.*symbolic link to/:/p'
+],
+[0],
+[abslink: /absolute/file/name
+dotdotlink: ../relative/file/name
+],
+[ignore])
+
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 24c27de..099c1e9 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -46,3 +46,6 @@ m4_include([CVE-2019-14866.at])
 
 m4_include([linktime.at])
 m4_include([linktime01.at])
+
+
+m4_include([symlink-tar-abs.at])
