Source-Changes-HG archive

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

[src/trunk]: src/bin/rcp allocate a separate buffer in each call to sink().



details:   https://anonhg.NetBSD.org/src/rev/c3de94ac1240
branches:  trunk
changeset: 779168:c3de94ac1240
user:      chs <chs%NetBSD.org@localhost>
date:      Mon May 07 15:22:54 2012 +0000

description:
allocate a separate buffer in each call to sink().
reusing the buffer across recursive calls just doesn't work right.

diffstat:

 bin/rcp/rcp.c |  24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diffs (83 lines):

diff -r 3eaedac5a950 -r c3de94ac1240 bin/rcp/rcp.c
--- a/bin/rcp/rcp.c     Mon May 07 13:14:31 2012 +0000
+++ b/bin/rcp/rcp.c     Mon May 07 15:22:54 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rcp.c,v 1.48 2009/08/31 07:11:16 dholland Exp $        */
+/*     $NetBSD: rcp.c,v 1.49 2012/05/07 15:22:54 chs Exp $     */
 
 /*
  * Copyright (c) 1983, 1990, 1992, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)rcp.c      8.2 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: rcp.c,v 1.48 2009/08/31 07:11:16 dholland Exp $");
+__RCSID("$NetBSD: rcp.c,v 1.49 2012/05/07 15:22:54 chs Exp $");
 #endif
 #endif /* not lint */
 
@@ -485,6 +485,8 @@
        char ch, *cp, *np, *targ, *vect[1], buf[BUFSIZ];
        const char *why;
        off_t size;
+       char *namebuf = NULL;
+       size_t cursize = 0;
 
 #define        atime   tv[0]
 #define        mtime   tv[1]
@@ -507,7 +509,7 @@
        for (first = 1;; first = 0) {
                cp = buf;
                if (read(rem, cp, 1) <= 0)
-                       return;
+                       goto out;
                if (*cp++ == '\n')
                        SCREWUP("unexpected <newline>");
                do {
@@ -528,7 +530,7 @@
                }
                if (buf[0] == 'E') {
                        (void)write(rem, "", 1);
-                       return;
+                       goto out;
                }
 
                if (ch == '\n')
@@ -582,20 +584,19 @@
                if (*cp++ != ' ')
                        SCREWUP("size not delimited");
                if (targisdir) {
-                       static char *namebuf;
-                       static size_t cursize;
                        char *newnamebuf;
                        size_t need;
 
-                       need = strlen(targ) + strlen(cp) + 250;
+                       need = strlen(targ) + strlen(cp) + 2;
                        if (need > cursize) {
+                               need += 256;
                                newnamebuf = realloc(namebuf, need);
                                if (newnamebuf != NULL) {
                                        namebuf = newnamebuf;
                                        cursize = need;
                                } else {
-                                       /* note: run_err is not fatal */
                                        run_err("%s", strerror(errno));
+                                       exit(1);
                                }
                        }
                        (void)snprintf(namebuf, cursize, "%s%s%s", targ,
@@ -726,6 +727,13 @@
                        break;
                }
        }
+
+out:
+       if (namebuf) {
+               free(namebuf);
+       }
+       return;
+
 screwup:
        run_err("protocol error: %s", why);
        exit(1);



Home | Main Index | Thread Index | Old Index