summaryrefslogtreecommitdiffstats
path: root/bin/rcp/rcp.c
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>2002-10-06 09:09:27 +0000
committercharnier <charnier@FreeBSD.org>2002-10-06 09:09:27 +0000
commita6e37dc9198254af864dbf54f93d1149a26e9b51 (patch)
tree36c289c3a806d20edb4775ddb19ee5787100dfa3 /bin/rcp/rcp.c
parent7e81d9c8895c5a191873642d607ff2af18d95efb (diff)
downloadFreeBSD-src-a6e37dc9198254af864dbf54f93d1149a26e9b51.zip
FreeBSD-src-a6e37dc9198254af864dbf54f93d1149a26e9b51.tar.gz
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.
Diffstat (limited to 'bin/rcp/rcp.c')
-rw-r--r--bin/rcp/rcp.c27
1 files changed, 11 insertions, 16 deletions
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 <sys/cdefs.h>
__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;
OpenPOWER on IntegriCloud