diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-11-08 11:20:32 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-11-08 11:20:32 +0200 |
commit | b1c85839bf1381f749dd45bf6a5a38924e3315a0 (patch) | |
tree | db6c001adc1c4ee93eddca3c542d6b7f39adcead /src/copyin.c | |
parent | 684b7ac5767e676cda78c161aeb7fe7b45a07529 (diff) | |
download | cpio-b1c85839bf1381f749dd45bf6a5a38924e3315a0.tar.gz cpio-b1c85839bf1381f749dd45bf6a5a38924e3315a0.tar.bz2 |
Improve 684b7ac5
* src/copyin.c (read_name_from_file): Handle len == 0.
Diffstat (limited to 'src/copyin.c')
-rw-r--r-- | src/copyin.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/copyin.c b/src/copyin.c index 9348923..2e7feb1 100644 --- a/src/copyin.c +++ b/src/copyin.c @@ -998,16 +998,22 @@ read_in_header (struct cpio_file_stat *file_hdr, int in_des) static void read_name_from_file (struct cpio_file_stat *file_hdr, int fd, uintmax_t len) { - cpio_realloc_c_name (file_hdr, len); - tape_buffered_read (file_hdr->c_name, fd, len); - if (file_hdr->c_name[len-1] == 0) - file_hdr->c_namesize = len; + if (len == 0) + { + error (0, 0, _("malformed header: file name of zero length")); + } else { - error (0, 0, _("malformed header: file name is not nul-terminated")); - /* Skip this file */ - file_hdr->c_namesize = 0; + cpio_realloc_c_name (file_hdr, len); + tape_buffered_read (file_hdr->c_name, fd, len); + if (file_hdr->c_name[len-1] != 0) + { + error (0, 0, _("malformed header: file name is not nul-terminated")); + /* Skip this file */ + len = 0; + } } + file_hdr->c_namesize = len; } /* Fill in FILE_HDR by reading an old-format ASCII format cpio header from |