From a6e37dc9198254af864dbf54f93d1149a26e9b51 Mon Sep 17 00:00:00 2001 From: charnier Date: Sun, 6 Oct 2002 09:09:27 +0000 Subject: While removing a memory leak, rev 1.32 introduced a free-memory-and-reuse-it-after. Correct both problems and make rcp -r work again under /etc/malloc.conf -> AJ. --- bin/rcp/rcp.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'bin/rcp') diff --git a/bin/rcp/rcp.c b/bin/rcp/rcp.c index b18bbc3..d86fec0 100644 --- a/bin/rcp/rcp.c +++ b/bin/rcp/rcp.c @@ -44,11 +44,12 @@ static char const copyright[] = The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ -#ifndef lint #if 0 +#ifndef lint static char sccsid[] = "@(#)rcp.c 8.2 (Berkeley) 4/2/94"; -#endif #endif /* not lint */ +#endif + #include __FBSDID("$FreeBSD$"); @@ -590,7 +591,7 @@ sink(int argc, char *argv[]) off_t i, j, size; int amt, count, exists, first, mask, mode, ofd, omode; int setimes, targisdir, wrerrno = 0; - char ch, *cp, *np, *targ, *why, *vect[1], buf[BUFSIZ]; + char ch, *cp, *np, *targ, *why, *vect[1], buf[BUFSIZ], path[PATH_MAX]; #define atime tv[0] #define mtime tv[1] @@ -687,21 +688,15 @@ sink(int argc, char *argv[]) if (*cp++ != ' ') SCREWUP("size not delimited"); if (targisdir) { - static char *namebuf = NULL; - static size_t cursize; - size_t need; - - need = strlen(targ) + strlen(cp) + 250; - if (need > cursize) { - if (namebuf != NULL) - free(namebuf); - if (!(namebuf = malloc(need))) - run_err("%s", strerror(errno)); - cursize = need; + if (strlen(targ) + (*targ ? 1 : 0) + strlen(cp) + >= sizeof(path)) { + run_err("%s%s%s: name too long", targ, + *targ ? "/" : "", cp); + exit(1); } - (void)snprintf(namebuf, need, "%s%s%s", targ, + (void)snprintf(path, sizeof(path), "%s%s%s", targ, *targ ? "/" : "", cp); - np = namebuf; + np = path; } else np = targ; exists = stat(np, &stb) == 0; -- cgit v1.1