blob: ec8b303c43af313436b56ce05acd0fd73279e831 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001Upstream-Status: Backport
Brad Bishopa5c52ff2018-11-23 10:55:50 +13002Signed-off-by: Ross Burton <ross.burton@intel.com>
3
Brad Bishop19323692019-04-05 15:28:33 -04004From 32d95fe0c90c59352a0ce3102fc9866cbfb0f629 Mon Sep 17 00:00:00 2001
5From: Sergey Poznyakoff <gray@gnu.org>
6Date: Sat, 1 Dec 2018 11:40:02 +0200
7Subject: [PATCH] Fix sigfault when appending to archive
Brad Bishopa5c52ff2018-11-23 10:55:50 +13008
Brad Bishop19323692019-04-05 15:28:33 -04009Bug reported by Ross Burton. See
10<http://lists.gnu.org/archive/html/bug-cpio/2018-11/msg00000.html>
Brad Bishopa5c52ff2018-11-23 10:55:50 +130011
Brad Bishop19323692019-04-05 15:28:33 -040012* src/util.c: Keep static copy of the buffer pointer; always
13assign it to file_hdr->c_name. Use x2realloc for memory management.
Brad Bishopa5c52ff2018-11-23 10:55:50 +130014---
Brad Bishop19323692019-04-05 15:28:33 -040015 src/util.c | 17 ++++-------------
16 1 file changed, 4 insertions(+), 13 deletions(-)
Brad Bishopa5c52ff2018-11-23 10:55:50 +130017
Brad Bishopa5c52ff2018-11-23 10:55:50 +130018diff --git a/src/util.c b/src/util.c
Brad Bishop19323692019-04-05 15:28:33 -040019index 10486dc..4e49124 100644
Brad Bishopa5c52ff2018-11-23 10:55:50 +130020--- a/src/util.c
21+++ b/src/util.c
Brad Bishop19323692019-04-05 15:28:33 -040022@@ -1413,22 +1413,13 @@ set_file_times (int fd,
Brad Bishopa5c52ff2018-11-23 10:55:50 +130023 void
24 cpio_set_c_name (struct cpio_file_stat *file_hdr, char *name)
25 {
Brad Bishop19323692019-04-05 15:28:33 -040026+ static char *buf = NULL;
27 static size_t buflen = 0;
Brad Bishopa5c52ff2018-11-23 10:55:50 +130028 size_t len = strlen (name) + 1;
29
Brad Bishop19323692019-04-05 15:28:33 -040030- if (buflen == 0)
31- {
32- buflen = len;
33- if (buflen < 32)
34- buflen = 32;
35- file_hdr->c_name = xmalloc (buflen);
36- }
37- else if (buflen < len)
38- {
39- buflen = len;
40- file_hdr->c_name = xrealloc (file_hdr->c_name, buflen);
41- }
42-
43+ while (buflen < len)
44+ buf = x2realloc (buf, &buflen);
45+ file_hdr->c_name = buf;
Brad Bishopa5c52ff2018-11-23 10:55:50 +130046 file_hdr->c_namesize = len;
Brad Bishopa5c52ff2018-11-23 10:55:50 +130047 memmove (file_hdr->c_name, name, len);
48 }
Brad Bishopa5c52ff2018-11-23 10:55:50 +130049--
Brad Bishop19323692019-04-05 15:28:33 -0400502.18.0
Brad Bishopa5c52ff2018-11-23 10:55:50 +130051