void-packages/srcpkgs/cpio/patches/0004-Fix-sigfault-when-appending-to-archive.patch

48 lines
1.3 KiB
Diff

From ea9b0ecd469afe005137f6955b6237bcc252397b Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Sat, 1 Dec 2018 11:40:02 +0200
Subject: [PATCH 4/4] 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 src/util.c src/util.c
index 4f3c073..41916d4 100644
--- src/util.c
+++ src/util.c
@@ -1414,22 +1414,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.20.1