cpio: Use getline in cpio_rename

The buffer has a fixed 1024 limit, which can be smaller than the maximum
allowed path length. Increasing the limit to 4096 would partially help,
but since leading spaces are stripped, input lines could be valid and
longer.

Use getline instead.
This commit is contained in:
Tobias Stoeckmann committed 2026-03-16 09:43:54 +01:00
1 parent 1ea5604e3e
commit ef1744a352
2 files changed
+12 -4

No files matched your search

+2
View File
@@ -15,6 +15,8 @@ IF(ENABLE_CPIO)
cpio_platform.h
../libarchive_fe/lafe_err.c
../libarchive_fe/lafe_err.h
../libarchive_fe/lafe_getline.c
../libarchive_fe/lafe_getline.h
../libarchive_fe/lafe_platform.h
../libarchive_fe/line_reader.c
../libarchive_fe/line_reader.h
+10 -4
View File
@@ -8,6 +8,8 @@
#include "cpio_platform.h"
#include "lafe_getline.h"
#include <sys/types.h>
#include <archive.h>
#include <archive_entry.h>
@@ -1293,9 +1295,10 @@ mode_pass(struct cpio *cpio, const char *destdir)
void
cpio_rename(struct archive_entry *entry)
{
char buff[1024];
char *buff = NULL, *p, *ret = NULL;
FILE *t;
char *p, *ret = NULL;
size_t n = 0;
ssize_t r;
#if defined(_WIN32) && !defined(__CYGWIN__)
FILE *to;
@@ -1317,11 +1320,12 @@ cpio_rename(struct archive_entry *entry)
fflush(t);
#endif
p = fgets(buff, sizeof(buff), t);
r = getline(&buff, &n, t);
fclose(t);
if (p == NULL)
if (r < 1)
/* End-of-file is a blank line. */
goto done;
p = buff;
while (*p == ' ' || *p == '\t')
++p;
@@ -1330,6 +1334,7 @@ cpio_rename(struct archive_entry *entry)
goto done;
if (*p == '.' && p[1] == '\n') {
/* Single period preserves original name. */
free(buff);
return;
}
ret = p;
@@ -1340,6 +1345,7 @@ cpio_rename(struct archive_entry *entry)
*p = '\0';
done:
archive_entry_set_pathname(entry, ret);
free(buff);
}
static void