From da82a07e932bd0eced160ee52fb75e87af4b14c5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 16 Aug 1999 08:13:20 +0000 Subject: [PATCH] Fix bugs when interpreting POSIX-compliant headers that do not contain null bytes in the header or link names. --- src/list.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/list.c b/src/list.c index 4bca28c..1c24531 100644 --- a/src/list.c +++ b/src/list.c @@ -386,7 +386,6 @@ read_header (void) else current_stat.st_size = OFF_FROM_CHARS (header->header.size); - header->header.name[NAME_FIELD_SIZE - 1] = '\0'; if (header->header.typeflag == GNUTYPE_LONGNAME || header->header.typeflag == GNUTYPE_LONGLINK) { @@ -425,18 +424,19 @@ read_header (void) } else { - char *name = next_long_name; + char *name; struct posix_header *h = ¤t_header->header; - char namebuf[sizeof h->prefix + 1 + sizeof h->name + 1]; + char namebuf[sizeof h->prefix + 1 + NAME_FIELD_SIZE + 1]; + name = next_long_name; if (! name) { /* Accept file names as specified by POSIX.1-1996 section 10.1.1. */ - int is_posix = (strcmp (h->magic, TMAGIC) == 0); + int posix_header = strcmp (h->magic, TMAGIC) == 0; char *np = namebuf; - if (is_posix && h->prefix[0]) + if (posix_header && h->prefix[0]) { memcpy (np, h->prefix, sizeof h->prefix); np[sizeof h->prefix] = '\0'; @@ -447,11 +447,17 @@ read_header (void) np[sizeof h->name] = '\0'; name = namebuf; } - assign_string (¤t_file_name, name); - assign_string (¤t_link_name, - (next_long_link ? next_long_link - : current_header->header.linkname)); + + name = next_long_link; + if (! name) + { + memcpy (namebuf, h->linkname, sizeof h->linkname); + namebuf[sizeof h->linkname] = '\0'; + name = namebuf; + } + assign_string (¤t_link_name, name); + next_long_link = next_long_name = 0; return HEADER_SUCCESS; } -- 2.45.2