Source-Changes-HG archive

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

[src/netbsd-2-0]: src/bin/pax Pullup rev 1.52 (requested by christos in ticke...



details:   https://anonhg.NetBSD.org/src/rev/679137593b1c
branches:  netbsd-2-0
changeset: 562798:679137593b1c
user:      jmc <jmc%NetBSD.org@localhost>
date:      Fri Nov 12 05:02:13 2004 +0000

description:
Pullup rev 1.52 (requested by christos in ticket #921)

Keep track of the length of the gnu long name/link hack, so that
we can append to it. Modify the code so that file_write is re-entrant,
even in the gnu long name/link hack.

diffstat:

 bin/pax/file_subs.c |  20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diffs (60 lines):

diff -r c33239938ed4 -r 679137593b1c bin/pax/file_subs.c
--- a/bin/pax/file_subs.c       Fri Nov 12 05:02:09 2004 +0000
+++ b/bin/pax/file_subs.c       Fri Nov 12 05:02:13 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: file_subs.c,v 1.41.2.7 2004/08/25 02:44:45 jmc Exp $   */
+/*     $NetBSD: file_subs.c,v 1.41.2.8 2004/11/12 05:02:13 jmc Exp $   */
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)file_subs.c        8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: file_subs.c,v 1.41.2.7 2004/08/25 02:44:45 jmc Exp $");
+__RCSID("$NetBSD: file_subs.c,v 1.41.2.8 2004/11/12 05:02:13 jmc Exp $");
 #endif
 #endif /* not lint */
 
@@ -917,6 +917,7 @@
        int wcnt;
        char *st = str;
        char **strp;
+       size_t *lenp;
 
        /*
         * while we have data to process
@@ -978,24 +979,27 @@
                switch (fd) {
                case -1:
                        strp = &gnu_name_string;
+                       lenp = &gnu_name_length;
                        break;
                case -2:
                        strp = &gnu_link_string;
+                       lenp = &gnu_link_length;
                        break;
                default:
                        strp = NULL;
+                       lenp = NULL;
                        break;
                }
                if (strp) {
-                       if (*strp)
-                               err(1, "WARNING! Major Internal Error! GNU hack Failing!");
-                       *strp = malloc(wcnt + 1);
-                       if (*strp == NULL) {
+                       char *nstr = *strp ? realloc(*strp, *lenp + wcnt + 1) :
+                               malloc(wcnt + 1);
+                       if (nstr == NULL) {
                                tty_warn(1, "Out of memory");
                                return(-1);
                        }
-                       strlcpy(*strp, st, wcnt);
-                       break;
+                       (void)strlcpy(&nstr[*lenp], st, wcnt + 1);
+                       *strp = nstr;
+                       *lenp += wcnt;
                } else if (xwrite(fd, st, wcnt) != wcnt) {
                        syswarn(1, errno, "Failed write to file %s", name);
                        return(-1);



Home | Main Index | Thread Index | Old Index