diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-12-01 11:40:02 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-12-01 11:41:56 +0200 |
commit | 32d95fe0c90c59352a0ce3102fc9866cbfb0f629 (patch) | |
tree | 73de253137d2dd57e523a8e4a02d5e94345d77a9 /src | |
parent | 13455ca3404a56013eec525621903acd1c33ec5e (diff) | |
download | cpio-32d95fe0c90c59352a0ce3102fc9866cbfb0f629.tar.gz cpio-32d95fe0c90c59352a0ce3102fc9866cbfb0f629.tar.bz2 |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/util.c | 17 |
1 files changed, 4 insertions, 13 deletions
@@ -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); } |