Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/gzip Fix a reference to stale storage on the stack -...
details: https://anonhg.NetBSD.org/src/rev/5b039fb51e07
branches: trunk
changeset: 566694:5b039fb51e07
user: agc <agc%NetBSD.org@localhost>
date: Mon May 17 18:10:33 2004 +0000
description:
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.
diffstat:
usr.bin/gzip/gzip.c | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
diffs (54 lines):
diff -r f7fbe65bb573 -r 5b039fb51e07 usr.bin/gzip/gzip.c
--- a/usr.bin/gzip/gzip.c Mon May 17 17:43:08 2004 +0000
+++ b/usr.bin/gzip/gzip.c Mon May 17 18:10:33 2004 +0000
@@ -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 @@
(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 @@
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 @@
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;
}
Home |
Main Index |
Thread Index |
Old Index