Blame SOURCES/cpio-2.11-recovery.patch

f0f11f
From 5e1e4fae6a9eab069866eb46b2f91d60fae34efe Mon Sep 17 00:00:00 2001
f0f11f
From: Sergey Poznyakoff <gray@gnu.org.ua>
f0f11f
Date: Thu, 11 Dec 2014 12:51:21 +0200
f0f11f
Subject: [PATCH] Fix error recovery in copy-in mode
f0f11f
f0f11f
(+ complete sync of symlink-bad-length.at test)
f0f11f
f0f11f
* src/copyin.c (copyin_link): Fix null dereference.
f0f11f
(read_in_header): Fix error recovery (bug introduced by
f0f11f
27e0ae55).
f0f11f
* tests/symlink-bad-length.at: Test error recovery.
f0f11f
Catch various architecture-dependent error messages (suggested
f0f11f
by Pavel Raiskup).
f0f11f
---
f0f11f
 src/copyin.c                | 10 ++++++----
f0f11f
 tests/symlink-bad-length.at | 16 ++++++++++++----
f0f11f
 2 files changed, 18 insertions(+), 8 deletions(-)
f0f11f
f0f11f
diff --git a/src/copyin.c b/src/copyin.c
f0f11f
index 29d0fb1..274bd49 100644
f0f11f
--- a/src/copyin.c
f0f11f
+++ b/src/copyin.c
f0f11f
@@ -655,7 +655,7 @@ copyin_device (struct cpio_file_stat* file_hdr)
f0f11f
 }
f0f11f
 
f0f11f
 static void
f0f11f
-copyin_link(struct cpio_file_stat *file_hdr, int in_file_des)
f0f11f
+copyin_link (struct cpio_file_stat *file_hdr, int in_file_des)
f0f11f
 {
f0f11f
   char *link_name = NULL;	/* Name of hard and symbolic links.  */
f0f11f
   int res;			/* Result of various function calls.  */
f0f11f
@@ -666,6 +666,8 @@ copyin_link(struct cpio_file_stat *file_hdr, int in_file_des)
f0f11f
   if (archive_format != arf_tar && archive_format != arf_ustar)
f0f11f
     {
f0f11f
       link_name = get_link_name (file_hdr, in_file_des);
f0f11f
+      if (!link_name)
f0f11f
+	return;
f0f11f
     }
f0f11f
   else
f0f11f
     {
f0f11f
@@ -1020,7 +1022,7 @@ read_in_header (struct cpio_file_stat *file_hdr, int in_des)
f0f11f
 
f0f11f
   file_hdr->c_tar_linkname = NULL;
f0f11f
 
f0f11f
-  tape_buffered_read (magic.str, in_des, 6L);
f0f11f
+  tape_buffered_read (magic.str, in_des, sizeof (magic.str));
f0f11f
   while (1)
f0f11f
     {
f0f11f
       if (append_flag)
f0f11f
@@ -1065,8 +1067,8 @@ read_in_header (struct cpio_file_stat *file_hdr, int in_des)
f0f11f
 	  break;
f0f11f
 	}
f0f11f
       bytes_skipped++;
f0f11f
-      memmove (magic.str, magic.str + 1, 5);
f0f11f
-      tape_buffered_read (magic.str, in_des, 1L);
f0f11f
+      memmove (magic.str, magic.str + 1, sizeof (magic.str) - 1);
f0f11f
+      tape_buffered_read (magic.str + sizeof (magic.str) - 1, in_des, 1L);
f0f11f
     }
f0f11f
 }
f0f11f
 
f0f11f
diff --git a/tests/symlink-bad-length.at b/tests/symlink-bad-length.at
f0f11f
index 84123a4..fd2c87e 100644
f0f11f
--- a/tests/symlink-bad-length.at
f0f11f
+++ b/tests/symlink-bad-length.at
f0f11f
@@ -1,5 +1,5 @@
f0f11f
 # Process this file with autom4te to create testsuite.  -*- Autotest -*-
f0f11f
-# Copyright (C) 2014 Free Software Foundation, Inc.
f0f11f
+# Copyright (C) 2014-2015, 2017 Free Software Foundation, Inc.
f0f11f
 
f0f11f
 # This program is free software; you can redistribute it and/or modify
f0f11f
 # it under the terms of the GNU General Public License as published by
f0f11f
@@ -35,18 +35,26 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
f0f11f
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
f0f11f
 ])
f0f11f
 
f0f11f
+# The exact error message and exit status depend on the host architecture,
f0f11f
+# therefore strderr is filtered out and error code is not checked.
f0f11f
+
f0f11f
+# So far the only case when cpio would exit with code 0 is when it skips
f0f11f
+# several bytes and encounters a valid record header.  Perhaps it should
f0f11f
+# exit with code 2 (non-critical error), if at least one byte was skipped,
f0f11f
+# but that could hurt backward compatibility.
f0f11f
+
f0f11f
 AT_CHECK([
f0f11f
 base64 -d ARCHIVE.base64 > ARCHIVE || AT_SKIP_TEST
f0f11f
-TZ=UTC cpio -ntv < ARCHIVE 2>stderr
f0f11f
-rc=$?
f0f11f
+TZ=UTC cpio -ntv < ARCHIVE 2>stderr 
f0f11f
 cat stderr | grep -v \
f0f11f
     -e 'stored filename length is out of range' \
f0f11f
     -e 'premature end of file' \
f0f11f
     -e 'archive header has reverse byte-order' \
f0f11f
     -e 'memory exhausted' \
f0f11f
+    -e 'skipped [[0-9][0-9]*] bytes of junk' \
f0f11f
+    -e '[[0-9][0-9]*] block' \
f0f11f
     >&2
f0f11f
 echo >&2 STDERR
f0f11f
-test "$rc" -ne 0
f0f11f
 ],
f0f11f
 [0],
f0f11f
 [-rw-rw-r--   1 10029    10031          13 Nov 25  2014 FILE
f0f11f
-- 
f0f11f
2.9.3
f0f11f