diff --git a/usr.bin/gzip/gzip.1 b/usr.bin/gzip/gzip.1 index 748bce86009f..723c675c2899 100644 --- a/usr.bin/gzip/gzip.1 +++ b/usr.bin/gzip/gzip.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: gzip.1,v 1.23 2014/03/18 18:20:45 riastradh Exp $ +.\" $NetBSD: gzip.1,v 1.25 2015/04/06 21:41:17 wiz Exp $ .\" .\" Copyright (c) 1997, 2003, 2004 Matthew R. Green .\" All rights reserved. @@ -25,7 +25,7 @@ .\" SUCH DAMAGE. .\" .\" $FreeBSD$ -.Dd October 9, 2011 +.Dd April 6, 2015 .Dt GZIP 1 .Os .Sh NAME @@ -105,9 +105,10 @@ options are enabled. This version of .Nm is also capable of decompressing files compressed using -.Xr compress 1 +.Xr compress 1 , +.Xr bzip2 1 , or -.Xr bzip2 1 . +.Xr xz 1 . .Sh OPTIONS The following options are available: .Bl -tag -width XXrXXXrecursiveX diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c index 9f92b6af8108..495392be381e 100644 --- a/usr.bin/gzip/gzip.c +++ b/usr.bin/gzip/gzip.c @@ -1,4 +1,4 @@ -/* $NetBSD: gzip.c,v 1.106 2014/10/18 08:33:30 snj Exp $ */ +/* $NetBSD: gzip.c,v 1.108 2015/04/15 02:29:12 christos Exp $ */ /*- * Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green @@ -158,7 +158,7 @@ static suffixes_t suffixes[] = { #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0]) #define SUFFIX_MAXLEN 30 -static const char gzip_version[] = "FreeBSD gzip 20141022"; +static const char gzip_version[] = "FreeBSD gzip 20150413"; #ifndef SMALL static const char gzip_copyright[] = \ @@ -1354,7 +1354,7 @@ file_uncompress(char *file, char *outfile, size_t outsize) #ifndef SMALL ssize_t rv; time_t timestamp = 0; - unsigned char name[PATH_MAX + 1]; + char name[PATH_MAX + 1]; #endif /* gather the old name info */ @@ -1409,21 +1409,33 @@ file_uncompress(char *file, char *outfile, size_t outsize) timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0]; if (header1[3] & ORIG_NAME) { - rbytes = pread(fd, name, sizeof name, GZIP_ORIGNAME); + rbytes = pread(fd, name, sizeof(name) - 1, GZIP_ORIGNAME); if (rbytes < 0) { maybe_warn("can't read %s", file); goto lose; } - if (name[0] != 0) { + if (name[0] != '\0') { + char *dp, *nf; + + /* Make sure that name is NUL-terminated */ + name[rbytes] = '\0'; + + /* strip saved directory name */ + nf = strrchr(name, '/'); + if (nf == NULL) + nf = name; + else + nf++; + /* preserve original directory name */ - char *dp = strrchr(file, '/'); + dp = strrchr(file, '/'); if (dp == NULL) dp = file; else dp++; snprintf(outfile, outsize, "%.*s%.*s", (int) (dp - file), - file, (int) rbytes, name); + file, (int) rbytes, nf); } } } @@ -2110,7 +2122,7 @@ static void display_license(void) { - fprintf(stderr, "%s (based on NetBSD gzip 20141018)\n", gzip_version); + fprintf(stderr, "%s (based on NetBSD gzip 20150113)\n", gzip_version); fprintf(stderr, "%s\n", gzip_copyright); exit(0); }