Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-2-0]: src/usr.bin/gzip Pull up revision 1.44 (requested by mrg in...



details:   https://anonhg.NetBSD.org/src/rev/69e9ad4063f4
branches:  netbsd-2-0
changeset: 561227:69e9ad4063f4
user:      tron <tron%NetBSD.org@localhost>
date:      Sun May 30 14:45:06 2004 +0000

description:
Pull up revision 1.44 (requested by mrg in ticket #420):
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 86ebf2c137ba -r 69e9ad4063f4 usr.bin/gzip/gzip.c
--- a/usr.bin/gzip/gzip.c       Sun May 30 11:55:12 2004 +0000
+++ b/usr.bin/gzip/gzip.c       Sun May 30 14:45:06 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gzip.c,v 1.29.2.8 2004/05/10 14:39:00 tron Exp $       */
+/*     $NetBSD: gzip.c,v 1.29.2.9 2004/05/30 14:45:06 tron 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.29.2.8 2004/05/10 14:39:00 tron Exp $");
+__RCSID("$NetBSD: gzip.c,v 1.29.2.9 2004/05/30 14:45:06 tron 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