- Fix segfault in case if archive_entry_pathname() returns NULL - Enhance replace file prompt - Improve comment explaining masks in check_binary() - Update manpage: mention -P option, don't use contractions, mention that '-' filename is stdin, remove obsolete info about missing replace prompt Index: unzip.c @@ -220,6 +211,9 @@ char *str; size_t i, len; + if (path == NULL || path[0] == '\0') + return (NULL); + len = strlen(path); while (len && path[len - 1] == '/') len--; @@ -445,7 +439,13 @@ fprintf(stderr, "replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", *path); - fgets(buf, 4, stdin); + if (fgets(buf, sizeof(buf), stdin) == NULL) { + clearerr(stdin); + printf("NULL\n(EOF or read error, " + "treating as \"[N]one\"...)\n"); + n_opt = 1; + return -1; + } switch (*buf) { case 'A': o_opt = 1; @@ -483,7 +483,9 @@ * one white-listed byte has to be found. * * Black-listed: 0..6, 14..25, 28..31 + * 0xf3ffc07f = 11110011111111111100000001111111b * White-listed: 9..10, 13, >= 32 + * 0x00002600 = 00000000000000000010011000000000b * * See the proginfo/txtvsbin.txt in the zip sources for a detailed discussion. */ @@ -703,7 +700,11 @@ mode_t filetype; char *p, *q; - pathname = pathdup(archive_entry_pathname(e)); + if ((pathname = pathdup(archive_entry_pathname(e))) == NULL) { + warningx("skipping empty or unreadable filename entry"); + ac(archive_read_data_skip(a)); + return; + } filetype = archive_entry_filetype(e); /* sanity checks */ @@ -766,7 +767,11 @@ char *pathname; mode_t filetype; - pathname = pathdup(archive_entry_pathname(e)); + if ((pathname = pathdup(archive_entry_pathname(e))) == NULL) { + warningx("skipping empty or unreadable filename entry"); + ac(archive_read_data_skip(a)); + return; + } filetype = archive_entry_filetype(e); /* I don't think this can happen in a zipfile.. */ Index: unzip.1 @@ -38,8 +36,10 @@ .Op Fl aCcfjLlnopqtuvy .Op Fl d Ar dir .Op Fl x Ar pattern +.Op Fl P Ar password .Ar zipfile .Sh DESCRIPTION +.\" ... The following options are available: .Bl -tag -width Fl .It Fl a @@ -52,7 +52,7 @@ When extracting files from the zipfile, they are written to stdout. This is similar to .Fl p , -but doesn't suppress normal output. +but does not suppress normal output. .It Fl d Ar dir Extract files into the specified directory rather than the current directory. @@ -118,6 +128,10 @@ and .Fl u may be specified. +If specified filename is +.Qq - , +then data is read from +.Va stdin . .Sh ENVIRONMENT If the .Ev UNZIP_DEBUG @@ -181,14 +195,3 @@ .Xr archive 3 library developed by .An Tim Kientzle Aq Mt kientzle@FreeBSD.org . -.Sh BUGS -The -.Nm -utility currently does not support asking the user whether to -overwrite or skip a file that already exists on disk. -To be on the safe side, it will fail if it encounters a file that -already exists and neither the -.Fl n -nor the -.Fl o -command line option was specified.