X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Flist.c;h=a0e18542e9f95c5de5c3c5a98c762a90942cad4a;hb=aa985330d59a033156b0d793f880de952eafa4e5;hp=c5fd5f4b2970b423abfb52594ee9ce35531b9464;hpb=241bbee81b2136a216dab74ab1322ae6dd07555f;p=chaz%2Ftar diff --git a/src/list.c b/src/list.c index c5fd5f4..a0e1854 100644 --- a/src/list.c +++ b/src/list.c @@ -1,5 +1,5 @@ /* List a tar archive, with support routines for reading a tar archive. - Copyright (C) 1988, 92, 93, 94, 96, 97 Free Software Foundation, Inc. + Copyright 1988,92,93,94,96,97,98,1999 Free Software Foundation, Inc. Written by John Gilmore, on 1985-08-26. This program is free software; you can redistribute it and/or modify it @@ -14,12 +14,13 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., - 59 Place - Suite 330, Boston, MA 02111-1307, USA. */ + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Define to non-zero for forcing old ctime() instead of isotime(). */ #undef USE_OLD_CTIME #include "system.h" +#include #include #include @@ -28,12 +29,19 @@ ((unsigned char) (Char) >= '0' && (unsigned char) (Char) <= '7') #define ISSPACE(Char) (ISASCII (Char) && isspace (Char)) +#ifndef FNM_LEADING_DIR +# include +#endif + #include "common.h" union block *current_header; /* points to current archive header */ struct stat current_stat; /* stat struct corresponding */ enum archive_format current_format; /* recognized format */ +static uintmax_t from_oct PARAMS ((const char *, size_t, const char *, uintmax_t)); + + /*-----------------------------------. | Main loop for reading an archive. | `-----------------------------------*/ @@ -62,6 +70,12 @@ read_and (void (*do_something) ()) /* Valid header. We should decode next field (mode) first. Ensure incoming names are null terminated. */ + if (ending_file_option && + fnmatch (ending_file_option, current_file_name, + FNM_LEADING_DIR) == 0) { + goto all_done; + } + /* FIXME: This is a quick kludge before 1.12 goes out. */ current_stat.st_mtime = TIME_FROM_OCT (current_header->header.mtime); @@ -164,6 +178,7 @@ read_and (void (*do_something) ()) } break; } + all_done: ; apply_delayed_set_stat (); close_archive (); @@ -308,6 +323,7 @@ read_header (void) long unsigned_sum; /* the POSIX one :-) */ long signed_sum; /* the Sun one :-( */ long recorded_sum; + uintmax_t parsed_sum; char *p; union block *header; char **longp; @@ -323,8 +339,13 @@ read_header (void) if (!header) return HEADER_END_OF_FILE; - recorded_sum = UINTMAX_FROM_OCT (header->header.chksum); + parsed_sum = from_oct (header->header.chksum, + sizeof header->header.chksum, + (char *) 0, TYPE_MAXIMUM (long)); + if (parsed_sum == (uintmax_t) -1) + return HEADER_FAILURE; + recorded_sum = parsed_sum; unsigned_sum = 0; signed_sum = 0; p = header->buffer; @@ -404,9 +425,28 @@ read_header (void) } else { - assign_string (¤t_file_name, - (next_long_name ? next_long_name - : current_header->header.name)); + char *name = next_long_name; + struct posix_header *h = ¤t_header->header; + char namebuf[sizeof h->prefix + 1 + sizeof h->name + 1]; + + if (! name) + { + /* Accept file names as specified by POSIX.1-1996 + section 10.1.1. */ + char *np = namebuf; + if (h->prefix[0]) + { + memcpy (np, h->prefix, sizeof h->prefix); + np[sizeof h->prefix] = '\0'; + np += strlen (np); + *np++ = '/'; + } + memcpy (np, h->name, sizeof h->name); + 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)); @@ -518,8 +558,9 @@ from_oct (const char *where0, size_t digs0, const char *type, uintmax_t maxval) { if (digs == 0) { - ERROR ((0, 0, _("Blanks in header where octal %s value expected"), - type)); + if (type) + ERROR ((0, 0, _("Blanks in header where octal %s value expected"), + type)); return -1; } if (!ISSPACE (*where)) @@ -541,8 +582,23 @@ from_oct (const char *where0, size_t digs0, const char *type, uintmax_t maxval) if (digs != 0 && *where && !ISSPACE (*where)) { - ERROR ((0, 0, _("Header contains `%.*s' where octal %s value expected"), - (int) digs0, where0, type)); + if (type) + { + char buf[1000]; /* Big enough to represent any header. */ + static struct quoting_options *o; + + if (!o) + { + o = clone_quoting_options ((struct quoting_options *) 0); + set_quoting_style (o, escape_quoting_style); + } + + quotearg_buffer (buf, sizeof buf, where0, digs0, o); + ERROR ((0, 0, + _("Header contains \"%.*s\" where octal %s value expected"), + (int) sizeof buf, buf, type)); + } + return -1; } @@ -550,54 +606,55 @@ from_oct (const char *where0, size_t digs0, const char *type, uintmax_t maxval) return value; out_of_range: - ERROR ((0, 0, _("Octal value `%.*s' is out of range for %s"), - (int) digs0, where0, type)); + if (type) + ERROR ((0, 0, _("Octal value `%.*s' is out of range for %s"), + (int) digs0, where0, type)); return -1; } gid_t gid_from_oct (const char *p, size_t s) { - return from_oct (p, s, "gid_t", GID_MAX); + return from_oct (p, s, "gid_t", (uintmax_t) TYPE_MAXIMUM (gid_t)); } major_t major_from_oct (const char *p, size_t s) { - return from_oct (p, s, "major_t", MAJOR_MAX); + return from_oct (p, s, "major_t", (uintmax_t) TYPE_MAXIMUM (major_t)); } minor_t minor_from_oct (const char *p, size_t s) { - return from_oct (p, s, "minor_t", MINOR_MAX); + return from_oct (p, s, "minor_t", (uintmax_t) TYPE_MAXIMUM (minor_t)); } mode_t mode_from_oct (const char *p, size_t s) { - return from_oct (p, s, "mode_t", MODE_MAX); + return from_oct (p, s, "mode_t", (uintmax_t) TYPE_MAXIMUM (mode_t)); } off_t off_from_oct (const char *p, size_t s) { - return from_oct (p, s, "off_t", OFF_MAX); + return from_oct (p, s, "off_t", (uintmax_t) TYPE_MAXIMUM (off_t)); } size_t size_from_oct (const char *p, size_t s) { - return from_oct (p, s, "size_t", SIZE_MAX); + return from_oct (p, s, "size_t", (uintmax_t) TYPE_MAXIMUM (size_t)); } time_t time_from_oct (const char *p, size_t s) { - return from_oct (p, s, "time_t", TIME_MAX); + return from_oct (p, s, "time_t", (uintmax_t) TYPE_MAXIMUM (time_t)); } uid_t uid_from_oct (const char *p, size_t s) { - return from_oct (p, s, "uid_t", UID_MAX); + return from_oct (p, s, "uid_t", (uintmax_t) TYPE_MAXIMUM (uid_t)); } uintmax_t uintmax_from_oct (const char *p, size_t s) { - return from_oct (p, s, "uintmax_t", UINTMAX_MAX); + return from_oct (p, s, "uintmax_t", TYPE_MAXIMUM (uintmax_t)); } @@ -700,7 +757,8 @@ print_header (void) { char modes[11]; char *timestamp; - char uform[11], gform[11]; /* these hold formatted ints */ + /* These hold formatted ints. */ + char uform[UINTMAX_STRSIZE_BOUND], gform[UINTMAX_STRSIZE_BOUND]; char *user, *group; char size[2 * UINTMAX_STRSIZE_BOUND]; /* holds formatted size or major,minor */