summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1999-02-04 23:18:56 +0000
committermillert <millert@openbsd.org>1999-02-04 23:18:56 +0000
commitfbb35f5f4a93c1f6151e33c6e549f314f6b1820e (patch)
treeaccd578217abb6d67b16f72114caa612b0db74fb
parentReflect reality (diff)
downloadwireguard-openbsd-fbb35f5f4a93c1f6151e33c6e549f314f6b1820e.tar.xz
wireguard-openbsd-fbb35f5f4a93c1f6151e33c6e549f314f6b1820e.zip
Fix a serious memory consumption problem when running over directories
that contain many hard-linked files; johnh@isi.edu Also add an xstrdup() that behaves like xmalloc() on failure.
-rw-r--r--usr.bin/rdist/child.c6
-rw-r--r--usr.bin/rdist/client.c29
-rw-r--r--usr.bin/rdist/common.c26
-rw-r--r--usr.bin/rdist/defs.h9
-rw-r--r--usr.bin/rdist/distopt.c6
-rw-r--r--usr.bin/rdist/docmd.c6
-rw-r--r--usr.bin/rdist/message.c8
-rw-r--r--usr.bin/rdist/rdist.c14
-rw-r--r--usr.bin/rdistd/filesys-os.c8
-rw-r--r--usr.bin/rdistd/server.c6
10 files changed, 74 insertions, 44 deletions
diff --git a/usr.bin/rdist/child.c b/usr.bin/rdist/child.c
index 6640cb31483..dd99aa8d789 100644
--- a/usr.bin/rdist/child.c
+++ b/usr.bin/rdist/child.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: child.c,v 1.7 1998/06/26 21:20:58 millert Exp $ */
+/* $OpenBSD: child.c,v 1.8 1999/02/04 23:18:56 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: child.c,v 6.28 1996/02/22 19:30:09 mcooper Exp $";
#else
static char RCSid[] =
-"$OpenBSD: child.c,v 1.7 1998/06/26 21:20:58 millert Exp $";
+"$OpenBSD: child.c,v 1.8 1999/02/04 23:18:56 millert Exp $";
#endif
static char sccsid[] = "@(#)docmd.c 5.1 (Berkeley) 6/6/85";
@@ -151,7 +151,7 @@ static CHILD *copychild(child)
newc = (CHILD *) xmalloc(sizeof(CHILD));
- newc->c_name = strdup(child->c_name);
+ newc->c_name = xstrdup(child->c_name);
newc->c_readfd = child->c_readfd;
newc->c_pid = child->c_pid;
newc->c_state = child->c_state;
diff --git a/usr.bin/rdist/client.c b/usr.bin/rdist/client.c
index 978f5f460c4..25ef8006346 100644
--- a/usr.bin/rdist/client.c
+++ b/usr.bin/rdist/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.7 1998/06/26 21:21:00 millert Exp $ */
+/* $OpenBSD: client.c,v 1.8 1999/02/04 23:18:57 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: client.c,v 6.80 1996/02/28 20:34:27 mcooper Exp $";
#else
static char RCSid[] =
-"$OpenBSD: client.c,v 1.7 1998/06/26 21:21:00 millert Exp $";
+"$OpenBSD: client.c,v 1.8 1999/02/04 23:18:57 millert Exp $";
#endif
static char sccsid[] = "@(#)client.c";
@@ -216,7 +216,7 @@ static void addcmdspecialfile(starget, rname, destdir)
if (isokay) {
new = (struct namelist *) xmalloc(sizeof(struct namelist));
- new->n_name = strdup(rfile);
+ new->n_name = xstrdup(rfile);
new->n_next = updfilelist;
updfilelist = new;
}
@@ -307,6 +307,18 @@ int checkfilename(name)
return(0);
}
+void freelinkinfo(lp)
+ struct linkbuf *lp;
+{
+ if (lp->pathname)
+ free(lp->pathname);
+ if (lp->src)
+ free(lp->src);
+ if (lp->target)
+ free(lp->target);
+ free(lp);
+}
+
/*
* Save and retrieve hard link info
*/
@@ -315,6 +327,7 @@ static struct linkbuf *linkinfo(statp)
{
struct linkbuf *lp;
+ /* XXX - linear search doesn't scale with many links */
for (lp = ihead; lp != NULL; lp = lp->nextp)
if (lp->inum == statp->st_ino && lp->devnum == statp->st_dev) {
lp->count--;
@@ -327,12 +340,14 @@ static struct linkbuf *linkinfo(statp)
lp->inum = statp->st_ino;
lp->devnum = statp->st_dev;
lp->count = statp->st_nlink - 1;
- (void) strcpy(lp->pathname, target);
- (void) strcpy(lp->src, source);
+ lp->pathname = xstrdup(target);
+ lp->src = xstrdup(source);
if (Tdest)
- (void) strcpy(lp->target, Tdest);
+ lp->target = xstrdup(Tdest);
else
- *lp->target = CNULL;
+ lp->target = NULL;
+ if (!lp->pathname || !lp->src || !(Tdest && lp->target))
+ fatalerr("Cannot malloc memory in linkinfo.");
return(NULL);
}
diff --git a/usr.bin/rdist/common.c b/usr.bin/rdist/common.c
index 1fef1396a4e..f8f2844b4dc 100644
--- a/usr.bin/rdist/common.c
+++ b/usr.bin/rdist/common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: common.c,v 1.7 1998/06/26 21:29:13 millert Exp $ */
+/* $OpenBSD: common.c,v 1.8 1999/02/04 23:18:57 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: common.c,v 6.82 1998/03/23 23:27:33 michaelc Exp $";
#else
static char RCSid[] =
-"$OpenBSD: common.c,v 1.7 1998/06/26 21:29:13 millert Exp $";
+"$OpenBSD: common.c,v 1.8 1999/02/04 23:18:57 millert Exp $";
#endif
static char sccsid[] = "@(#)common.c";
@@ -117,7 +117,7 @@ extern void setprogname(argv)
register char *cp;
if (!progname) {
- progname = strdup(argv[0]);
+ progname = xstrdup(argv[0]);
if ((cp = strrchr(progname, '/')))
progname = cp + 1;
}
@@ -146,7 +146,7 @@ extern int init(argc, argv, envp)
realargc = argc;
realargv = (char **) xmalloc(sizeof(char *) * (argc+1));
for (i = 0; i < argc; i++)
- realargv[i] = strdup(argv[i]);
+ realargv[i] = xstrdup(argv[i]);
#if defined(SETARGS)
setargs_settup(argc, argv, envp);
@@ -161,8 +161,8 @@ extern int init(argc, argv, envp)
debugmsg(DM_MISC, "UserID = %d pwname = '%s' home = '%s'\n",
userid, pw->pw_name, pw->pw_dir);
- homedir = strdup(pw->pw_dir);
- locuser = strdup(pw->pw_name);
+ homedir = xstrdup(pw->pw_dir);
+ locuser = xstrdup(pw->pw_name);
groupid = pw->pw_gid;
gethostname(host, sizeof(host));
if ((cp = strchr(host, '.')) != NULL)
@@ -936,6 +936,20 @@ char *xcalloc(num, esize)
}
/*
+ * Strdup with error checking
+ */
+char *xstrdup(str)
+ char *str;
+{
+ char *nstr;
+
+ if ((nstr = strdup(str)) == NULL)
+ fatalerr("Cannot malloc %d bytes of memory.", strlen(str));
+
+ return(nstr);
+}
+
+/*
* Private version of basename()
*/
extern char *xbasename(path)
diff --git a/usr.bin/rdist/defs.h b/usr.bin/rdist/defs.h
index ae76052a6be..31f06ad1d7b 100644
--- a/usr.bin/rdist/defs.h
+++ b/usr.bin/rdist/defs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: defs.h,v 1.9 1998/07/16 20:40:23 millert Exp $ */
+/* $OpenBSD: defs.h,v 1.10 1999/02/04 23:18:57 millert Exp $ */
#ifndef __DEFS_H__
#define __DEFS_H__
@@ -298,9 +298,9 @@ struct linkbuf {
ino_t inum;
dev_t devnum;
int count;
- char pathname[BUFSIZ];
- char src[BUFSIZ];
- char target[BUFSIZ];
+ char *pathname;
+ char *src;
+ char *target;
struct linkbuf *nextp;
};
@@ -354,6 +354,7 @@ char *makestr();
char *xcalloc();
char *xmalloc();
char *xrealloc();
+char *xstrdup();
extern char *xbasename();
extern char *getdistoptlist();
extern char *getgroupname();
diff --git a/usr.bin/rdist/distopt.c b/usr.bin/rdist/distopt.c
index 99b62150b3b..5e08cbfb4ff 100644
--- a/usr.bin/rdist/distopt.c
+++ b/usr.bin/rdist/distopt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: distopt.c,v 1.4 1998/06/26 21:21:07 millert Exp $ */
+/* $OpenBSD: distopt.c,v 1.5 1999/02/04 23:18:57 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: distopt.c,v 6.10 1996/01/30 01:52:07 mcooper Exp $";
#else
static char RCSid[] =
-"$OpenBSD: distopt.c,v 1.4 1998/06/26 21:21:07 millert Exp $";
+"$OpenBSD: distopt.c,v 1.5 1999/02/04 23:18:57 millert Exp $";
#endif
static char sccsid[] = "@(#)distopt.c";
@@ -112,7 +112,7 @@ extern int parsedistopts(str, optptr, doerrs)
int negate;
/* strtok() is harmful */
- string = strdup(str);
+ string = xstrdup(str);
for (optstr = strtok(string, ","); optstr;
optstr = strtok(NULL, ",")) {
diff --git a/usr.bin/rdist/docmd.c b/usr.bin/rdist/docmd.c
index 04ac5a24f6f..3252a4eed55 100644
--- a/usr.bin/rdist/docmd.c
+++ b/usr.bin/rdist/docmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: docmd.c,v 1.7 1998/06/26 21:21:09 millert Exp $ */
+/* $OpenBSD: docmd.c,v 1.8 1999/02/04 23:18:57 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: docmd.c,v 6.86 1996/01/30 02:29:43 mcooper Exp $";
#else
static char RCSid[] =
-"$OpenBSD: docmd.c,v 1.7 1998/06/26 21:21:09 millert Exp $";
+"$OpenBSD: docmd.c,v 1.8 1999/02/04 23:18:57 millert Exp $";
#endif
static char sccsid[] = "@(#)docmd.c 5.1 (Berkeley) 6/6/85";
@@ -592,7 +592,7 @@ done:
if (!nflag) {
register struct linkbuf *nextl, *l;
- for (l = ihead; l != NULL; free((char *)l), l = nextl) {
+ for (l = ihead; l != NULL; freelinkinfo(l), l = nextl) {
nextl = l->nextp;
if (contimedout || IS_ON(opts, DO_IGNLNKS) ||
l->count == 0)
diff --git a/usr.bin/rdist/message.c b/usr.bin/rdist/message.c
index f3253a9d6a0..50e3182d4e4 100644
--- a/usr.bin/rdist/message.c
+++ b/usr.bin/rdist/message.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: message.c,v 1.7 1998/06/26 21:21:15 millert Exp $ */
+/* $OpenBSD: message.c,v 1.8 1999/02/04 23:18:57 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: message.c,v 6.24 1996/07/19 17:00:35 michaelc Exp $";
#else
static char RCSid[] =
-"$OpenBSD: message.c,v 1.7 1998/06/26 21:21:15 millert Exp $";
+"$OpenBSD: message.c,v 1.8 1999/02/04 23:18:57 millert Exp $";
#endif
static char sccsid[] = "@(#)common.c";
@@ -210,7 +210,7 @@ static char *setmsgtypes(msgfac, str)
if ((msgfac->mf_fptr = fopen(strptr, "w")) == NULL)
fatalerr("Cannot open log file for writing: %s: %s.",
strptr, SYSERR);
- msgfac->mf_filename = strdup(strptr);
+ msgfac->mf_filename = xstrdup(strptr);
strptr = cp;
break;
@@ -505,7 +505,7 @@ extern void checkhostname()
if (gethostname(mbuf, sizeof(mbuf)) == 0) {
if ((cp = strchr(mbuf, '.')) != NULL)
*cp = CNULL;
- currenthost = strdup(mbuf);
+ currenthost = xstrdup(mbuf);
} else
currenthost = "(unknown)";
}
diff --git a/usr.bin/rdist/rdist.c b/usr.bin/rdist/rdist.c
index 1ca225cca6e..c4b19bb2869 100644
--- a/usr.bin/rdist/rdist.c
+++ b/usr.bin/rdist/rdist.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rdist.c,v 1.6 1998/07/16 20:43:56 millert Exp $ */
+/* $OpenBSD: rdist.c,v 1.7 1999/02/04 23:18:57 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: rdist.c,v 6.65 1995/12/12 00:20:39 mcooper Exp $";
#else
static char RCSid[] =
-"$OpenBSD: rdist.c,v 1.6 1998/07/16 20:43:56 millert Exp $";
+"$OpenBSD: rdist.c,v 1.7 1999/02/04 23:18:57 millert Exp $";
#endif
static char sccsid[] = "@(#)main.c 5.1 (Berkeley) 6/6/85";
@@ -94,7 +94,7 @@ static void addhostlist(name, hostlist)
return;
new = (struct namelist *) xmalloc(sizeof(struct namelist));
- new->n_name = strdup(name);
+ new->n_name = xstrdup(name);
new->n_next = NULL;
if (*hostlist) {
@@ -174,7 +174,7 @@ main(argc, argv, envp)
break;
case 'L':
- remotemsglist = strdup(optarg);
+ remotemsglist = xstrdup(optarg);
break;
case 'A':
@@ -200,7 +200,7 @@ main(argc, argv, envp)
break;
case 'f':
- distfile = strdup(optarg);
+ distfile = xstrdup(optarg);
if (distfile[0] == '-' && distfile[1] == CNULL)
fin = stdin;
break;
@@ -246,7 +246,7 @@ main(argc, argv, envp)
error("No path specified to \"-p\".");
usage();
}
- path_rdistd = strdup(optarg);
+ path_rdistd = xstrdup(optarg);
break;
case 'P':
@@ -255,7 +255,7 @@ main(argc, argv, envp)
usage();
}
if ((cp = searchpath(optarg)))
- path_remsh = strdup(cp);
+ path_remsh = xstrdup(cp);
else {
error("No component of path \"%s\" exists.",
optarg);
diff --git a/usr.bin/rdistd/filesys-os.c b/usr.bin/rdistd/filesys-os.c
index 7202743c963..490510c7154 100644
--- a/usr.bin/rdistd/filesys-os.c
+++ b/usr.bin/rdistd/filesys-os.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filesys-os.c,v 1.5 1998/06/26 21:20:47 millert Exp $ */
+/* $OpenBSD: filesys-os.c,v 1.6 1999/02/04 23:18:57 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: filesys-os.c,v 6.17 1996/01/17 21:02:45 mcooper Exp mcooper $";
#else
static char RCSid[] =
-"$OpenBSD: filesys-os.c,v 1.5 1998/06/26 21:20:47 millert Exp $";
+"$OpenBSD: filesys-os.c,v 1.6 1999/02/04 23:18:57 millert Exp $";
#endif
static char sccsid[] = "@(#)filesys-os.c";
@@ -402,8 +402,8 @@ mntent_t *newmountent(old)
return(NULL);
new = (mntent_t *) xcalloc(1, sizeof(mntent_t));
- new->me_path = strdup(old->me_path);
- new->me_type = strdup(old->me_type);
+ new->me_path = xstrdup(old->me_path);
+ new->me_type = xstrdup(old->me_type);
new->me_flags = old->me_flags;
return(new);
diff --git a/usr.bin/rdistd/server.c b/usr.bin/rdistd/server.c
index 9781d7952fa..6c216b08110 100644
--- a/usr.bin/rdistd/server.c
+++ b/usr.bin/rdistd/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.7 1998/06/26 21:20:53 millert Exp $ */
+/* $OpenBSD: server.c,v 1.8 1999/02/04 23:18:57 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -38,7 +38,7 @@ static char RCSid[] =
"$From: server.c,v 6.85 1996/03/12 22:55:38 mcooper Exp $";
#else
static char RCSid[] =
-"$OpenBSD: server.c,v 1.7 1998/06/26 21:20:53 millert Exp $";
+"$OpenBSD: server.c,v 1.8 1999/02/04 23:18:57 millert Exp $";
#endif
static char sccsid[] = "@(#)server.c 5.3 (Berkeley) 6/7/86";
@@ -1313,7 +1313,7 @@ static void setconfig(cmd)
* Only use info if we don't know who this is.
*/
if (!fromhost) {
- fromhost = strdup(cp);
+ fromhost = xstrdup(cp);
message(MT_SYSLOG, "startup for %s", fromhost);
#if defined(SETARGS) || defined(HAVE_SETPROCTITLE)
setproctitle("serving %s", cp);