summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/cpio/cpio-2.12/0001-Fix-segfault-with-append.patch
blob: ec8b303c43af313436b56ce05acd0fd73279e831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Upstream-Status: Backport
Signed-off-by: Ross Burton <ross.burton@intel.com>

From 32d95fe0c90c59352a0ce3102fc9866cbfb0f629 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Sat, 1 Dec 2018 11:40:02 +0200
Subject: [PATCH] Fix sigfault when appending to archive

Bug reported by Ross Burton. See
<http://lists.gnu.org/archive/html/bug-cpio/2018-11/msg00000.html>

* src/util.c: Keep static copy of the buffer pointer; always
assign it to file_hdr->c_name. Use x2realloc for memory management.
---
 src/util.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/src/util.c b/src/util.c
index 10486dc..4e49124 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1413,22 +1413,13 @@ set_file_times (int fd,
 void
 cpio_set_c_name (struct cpio_file_stat *file_hdr, char *name)
 {
+  static char *buf = NULL;
   static size_t buflen = 0;
   size_t len = strlen (name) + 1;
 
-  if (buflen == 0)
-    {
-      buflen = len;
-      if (buflen < 32)
-        buflen = 32;
-      file_hdr->c_name = xmalloc (buflen);
-    }
-  else if (buflen < len)
-    {
-      buflen = len;
-      file_hdr->c_name = xrealloc (file_hdr->c_name, buflen);
-    }
-
+  while (buflen < len)
+    buf = x2realloc (buf, &buflen);
+  file_hdr->c_name = buf;
   file_hdr->c_namesize = len;
   memmove (file_hdr->c_name, name, len);
 }
-- 
2.18.0