Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | Upstream-Status: Backport |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 2 | Signed-off-by: Ross Burton <ross.burton@intel.com> |
| 3 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 4 | From 32d95fe0c90c59352a0ce3102fc9866cbfb0f629 Mon Sep 17 00:00:00 2001 |
| 5 | From: Sergey Poznyakoff <gray@gnu.org> |
| 6 | Date: Sat, 1 Dec 2018 11:40:02 +0200 |
| 7 | Subject: [PATCH] Fix sigfault when appending to archive |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 8 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 9 | Bug reported by Ross Burton. See |
| 10 | <http://lists.gnu.org/archive/html/bug-cpio/2018-11/msg00000.html> |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 11 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 12 | * src/util.c: Keep static copy of the buffer pointer; always |
| 13 | assign it to file_hdr->c_name. Use x2realloc for memory management. |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 14 | --- |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 15 | src/util.c | 17 ++++------------- |
| 16 | 1 file changed, 4 insertions(+), 13 deletions(-) |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 17 | |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 18 | diff --git a/src/util.c b/src/util.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 19 | index 10486dc..4e49124 100644 |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 20 | --- a/src/util.c |
| 21 | +++ b/src/util.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 22 | @@ -1413,22 +1413,13 @@ set_file_times (int fd, |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 23 | void |
| 24 | cpio_set_c_name (struct cpio_file_stat *file_hdr, char *name) |
| 25 | { |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 26 | + static char *buf = NULL; |
| 27 | static size_t buflen = 0; |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 28 | size_t len = strlen (name) + 1; |
| 29 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 30 | - 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 Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 46 | file_hdr->c_namesize = len; |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 47 | memmove (file_hdr->c_name, name, len); |
| 48 | } |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 49 | -- |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 50 | 2.18.0 |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 51 | |