diff options
| author | agc <agc@NetBSD.org> | 2004-05-17 18:10:33 +0000 |
|---|---|---|
| committer | agc <agc@NetBSD.org> | 2004-05-17 18:10:33 +0000 |
| commit | f8dc59869d70bdce602bc775eecd715dc2a63b3f (patch) | |
| tree | 7a26515a18471206bd8a2c374020ad64922ee09d | |
| parent | 1f358dcd03914391b180fe1a9b2cbf0431cc0a82 (diff) | |
Fix a reference to stale storage on the stack - malloc the new file
name when gunzip'ing via strdup(3). Fixes a bug whereby the new
filename would appear as gibberish when verbosely gunzipping.
Fix an off-by-one error when allocating the filename with added suffix,
and properly NUL-terminate the new filename.
It's NULL, not 0, in char * assignments - there are some still to do here.
| -rw-r--r-- | usr.bin/gzip/gzip.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c index 2b55496bbd8..3f5d5385240 100644 --- a/usr.bin/gzip/gzip.c +++ b/usr.bin/gzip/gzip.c @@ -1,4 +1,4 @@ -/* $NetBSD: gzip.c,v 1.43 2004/05/06 17:43:57 bouyer Exp $ */ +/* $NetBSD: gzip.c,v 1.44 2004/05/17 18:10:33 agc Exp $ */ /* * Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green @@ -32,7 +32,7 @@ #ifndef lint __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green\n\ All rights reserved.\n"); -__RCSID("$NetBSD: gzip.c,v 1.43 2004/05/06 17:43:57 bouyer Exp $"); +__RCSID("$NetBSD: gzip.c,v 1.44 2004/05/17 18:10:33 agc Exp $"); #endif /* not lint */ /* @@ -1170,7 +1170,7 @@ file_uncompress(char *file) (unsigned long long)osb.st_size); goto lose; } - newfile = outfile; + newfile = strdup(outfile); if (cflag == 0) unlink(file); size = osb.st_size; @@ -1301,7 +1301,7 @@ handle_stdout(void) static void handle_pathname(char *path) { - char *opath = path, *s = 0; + char *opath = path, *s = NULL; ssize_t len; struct stat sb; @@ -1316,13 +1316,14 @@ handle_pathname(char *path) retry: if (stat(path, &sb) < 0) { /* lets try <path>.gz if we're decompressing */ - if (dflag && s == 0 && errno == ENOENT) { + if (dflag && s == NULL && errno == ENOENT) { len = strlen(path); - s = malloc(len + suffix_len); - if (s == 0) + s = malloc(len + suffix_len + 1); + if (s == NULL) maybe_err(1, "malloc"); memmove(s, path, len); memmove(&s[len], suffix, suffix_len); + s[len + suffix_len] = 0x0; path = s; goto retry; } |
