summaryrefslogtreecommitdiff
path: root/usr.bin/rdist
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/rdist')
-rw-r--r--usr.bin/rdist/client.c10
-rw-r--r--usr.bin/rdist/common.c81
-rw-r--r--usr.bin/rdist/docmd.c35
-rw-r--r--usr.bin/rdist/expand.c22
-rw-r--r--usr.bin/rdist/message.c9
5 files changed, 82 insertions, 75 deletions
diff --git a/usr.bin/rdist/client.c b/usr.bin/rdist/client.c
index eba72701151..fd9f6ba13b5 100644
--- a/usr.bin/rdist/client.c
+++ b/usr.bin/rdist/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.15 2003/04/07 21:13:52 deraadt Exp $ */
+/* $OpenBSD: client.c,v 1.16 2003/04/19 17:22:29 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.15 2003/04/07 21:13:52 deraadt Exp $";
+"$OpenBSD: client.c,v 1.16 2003/04/19 17:22:29 millert Exp $";
#endif
static char sccsid[] = "@(#)client.c";
@@ -525,8 +525,8 @@ static int rmchk(opts)
* CC_NO -- file exists - DON'T remove.
* CC_YES -- file doesn't exist - REMOVE.
*/
- (void) sprintf(ptarget, "%s%s",
- (ptarget[-1] == '/' ? "" : "/"), s);
+ snprintf(ptarget, target + sizeof(target) - ptarget,
+ "%s%s", (ptarget[-1] == '/' ? "" : "/"), s);
debugmsg(DM_MISC, "check %s\n", target);
if (except(target))
(void) sendcmd(CC_NO, NULL);
@@ -1215,7 +1215,7 @@ extern int install(src, dest, ddir, destdir, opts)
debugmsg(DM_MISC, "%s\n", buff);
}
- rname = exptilde(target, src);
+ rname = exptilde(target, src, sizeof(target));
if (rname == NULL)
return(-1);
ptarget = target;
diff --git a/usr.bin/rdist/common.c b/usr.bin/rdist/common.c
index 2309216a1dc..6f963698e6e 100644
--- a/usr.bin/rdist/common.c
+++ b/usr.bin/rdist/common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: common.c,v 1.17 2003/04/05 20:31:58 deraadt Exp $ */
+/* $OpenBSD: common.c,v 1.18 2003/04/19 17:22:29 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.17 2003/04/05 20:31:58 deraadt Exp $";
+"$OpenBSD: common.c,v 1.18 2003/04/19 17:22:29 millert Exp $";
#endif
static char sccsid[] = "@(#)common.c";
@@ -296,9 +296,10 @@ extern void sighandler(sig)
* Function to actually send the command char and message to the
* remote host.
*/
-static int sendcmdmsg(cmd, msg)
+static int sendcmdmsg(cmd, msg, msgsize)
char cmd;
char *msg;
+ size_t msgsize;
{
int len;
@@ -309,7 +310,7 @@ static int sendcmdmsg(cmd, msg)
* All commands except C_NONE should have a newline
*/
if (cmd != C_NONE && !strchr(msg + 1, '\n'))
- (void) strcat(msg + 1, "\n");
+ (void) strlcat(msg + 1, "\n", msgsize - 1);
if (cmd == C_NONE)
len = strlen(msg);
@@ -342,12 +343,13 @@ extern int sendcmd(char cmd, char *fmt, ...)
va_start(args, fmt);
if (fmt)
- (void) vsprintf((cmd == C_NONE) ? buf : buf + 1, fmt, args);
+ (void) vsnprintf(buf + (cmd != C_NONE),
+ sizeof(buf) - (cmd != C_NONE), fmt, args);
else
buf[1] = CNULL;
va_end(args);
- return(sendcmdmsg(cmd, buf));
+ return(sendcmdmsg(cmd, buf, sizeof(buf)));
}
#endif /* ARG_TYPE == ARG_STDARG */
@@ -368,12 +370,13 @@ extern int sendcmd(va_alist)
cmd = (char) va_arg(args, int);
fmt = va_arg(args, char *);
if (fmt)
- (void) vsprintf((cmd == C_NONE) ? buf : buf + 1, fmt, args);
+ (void) vsnprintf(buf + (cmd != C_NONE),
+ sizeof(buf) - (cmd != C_NONE), fmt, args);
else
buf[1] = CNULL;
va_end(args);
- return(sendcmdmsg(cmd, buf));
+ return(sendcmdmsg(cmd, buf, sizeof(buf)));
}
#endif /* ARG_TYPE == ARG_VARARGS */
@@ -389,12 +392,13 @@ extern int sendcmd(cmd, fmt, a1, a2, a3, a4, a5, a6, a7, a8)
static char buf[BUFSIZ];
if (fmt)
- (void) sprintf((cmd == C_NONE) ? buf : buf + 1,
- fmt, a1, a2, a3, a4, a5, a6, a7, a8);
+ (void) snprintf(buf + (cmd != C_NONE),
+ sizeof(buf) - (cmd != C_NONE),
+ fmt, a1, a2, a3, a4, a5, a6, a7, a8);
else
buf[1] = CNULL;
- return(sendcmdmsg(cmd, buf));
+ return(sendcmdmsg(cmd, buf, sizeof(buf)));
}
#endif /* !ARG_TYPE */
@@ -668,52 +672,55 @@ extern int response()
* user's home directory path name. Return a pointer in buf to the
* part corresponding to `file'.
*/
-extern char *exptilde(ebuf, file)
+extern char *exptilde(ebuf, file, ebufsize)
char *ebuf;
+ size_t ebufsize;
char *file;
{
- char *s1, *s2, *s3;
+ char *pw_dir, *rest;
+ size_t len;
extern char *homedir;
if (*file != '~') {
- (void) strcpy(ebuf, file);
+notilde:
+ (void) strlcpy(ebuf, file, ebufsize);
return(ebuf);
}
if (*++file == CNULL) {
- s2 = homedir;
- s3 = NULL;
+ pw_dir = homedir;
+ rest = NULL;
} else if (*file == '/') {
- s2 = homedir;
- s3 = file;
+ pw_dir = homedir;
+ rest = file;
} else {
- s3 = file;
- while (*s3 && *s3 != '/')
- s3++;
- if (*s3 == '/')
- *s3 = CNULL;
+ rest = file;
+ while (*rest && *rest != '/')
+ rest++;
+ if (*rest == '/')
+ *rest = CNULL;
else
- s3 = NULL;
+ rest = NULL;
if (pw == NULL || strcmp(pw->pw_name, file) != 0) {
if ((pw = getpwnam(file)) == NULL) {
error("%s: unknown user name", file);
- if (s3 != NULL)
- *s3 = '/';
+ if (rest != NULL)
+ *rest = '/';
return(NULL);
}
}
- if (s3 != NULL)
- *s3 = '/';
- s2 = pw->pw_dir;
+ if (rest != NULL)
+ *rest = '/';
+ pw_dir = pw->pw_dir;
}
- for (s1 = ebuf; (*s1++ = *s2++); )
- ;
- s2 = --s1;
- if (s3 != NULL) {
- s2++;
- while ((*s1++ = *s3++))
- ;
+ if ((len = strlcpy(ebuf, pw_dir, ebufsize)) >= ebufsize)
+ goto notilde;
+ pw_dir = ebuf + len;
+ if (rest != NULL) {
+ pw_dir++;
+ if ((len = strlcat(ebuf, rest, ebufsize)) >= ebufsize)
+ goto notilde;
}
- return(s2);
+ return(pw_dir);
}
#if defined(DIRECT_RCMD)
diff --git a/usr.bin/rdist/docmd.c b/usr.bin/rdist/docmd.c
index 55c3a2ab32b..fdbe5801630 100644
--- a/usr.bin/rdist/docmd.c
+++ b/usr.bin/rdist/docmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: docmd.c,v 1.12 2003/04/05 20:31:58 deraadt Exp $ */
+/* $OpenBSD: docmd.c,v 1.13 2003/04/19 17:22:29 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.12 2003/04/05 20:31:58 deraadt Exp $";
+"$OpenBSD: docmd.c,v 1.13 2003/04/19 17:22:29 millert Exp $";
#endif
static char sccsid[] = "@(#)docmd.c 5.1 (Berkeley) 6/6/85";
@@ -64,7 +64,7 @@ struct namelist *filelist; /* list of source files */
extern struct cmd *cmds; /* Initialized by yyparse() */
time_t lastmod; /* Last modify time */
-extern char target[];
+extern char target[BUFSIZ];
extern char *ptarget;
extern int activechildren;
extern int maxchildren;
@@ -690,7 +690,7 @@ static void cmptime(name, sbcmds, env)
* first time cmptime() is called?
*/
if (ptarget == NULL) {
- if (exptilde(target, name) == NULL)
+ if (exptilde(target, name, sizeof(target)) == NULL)
return;
ptarget = name = target;
while (*ptarget)
@@ -721,12 +721,10 @@ static void cmptime(name, sbcmds, env)
E_LOCFILE, name, sc->sc_name);
message(MT_CHANGE, "special \"%s\"", buf);
if (*env) {
- int len = strlen(*env);
- *env = (char *) xrealloc(*env, len +
- strlen(name) + 2);
- *env[len] = CNULL;
- (void) strcat(*env, name);
- (void) strcat(*env, ":");
+ size_t len = strlen(*env) + strlen(name) + 2;
+ *env = (char *) xrealloc(*env, len);
+ (void) strlcat(*env, name, len);
+ (void) strlcat(*env, ":", len);
}
if (IS_ON(options, DO_VERIFY))
continue;
@@ -800,16 +798,13 @@ static void dodcolon(cmd, filev)
if (sc->sc_type == NOTIFY)
notify(NULL, sc->sc_args, (time_t)lastmod);
else if (sc->sc_type == CMDSPECIAL && env) {
- char *p;
- int len = strlen(env);
-
- env = xrealloc(env,
- len + strlen(sc->sc_name) + 2);
- env[len] = CNULL;
- if (*(p = &env[len - 1]) == ':')
- *p = CNULL;
- (void) strcat(env, "';");
- (void) strcat(env, sc->sc_name);
+ size_t len = strlen(env);
+ if (env[len - 1] == ':')
+ env[--len] = CNULL;
+ len += 2 + strlen(sc->sc_name) + 1;
+ env = xrealloc(env, len);
+ (void) strlcat(env, "';", len);
+ (void) strlcat(env, sc->sc_name, len);
message(MT_CHANGE, "cmdspecial \"%s\"", env);
if (!nflag && IS_OFF(options, DO_VERIFY))
runcommand(env);
diff --git a/usr.bin/rdist/expand.c b/usr.bin/rdist/expand.c
index 1eade9335aa..3ecd9eb8908 100644
--- a/usr.bin/rdist/expand.c
+++ b/usr.bin/rdist/expand.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: expand.c,v 1.8 2003/04/05 20:31:58 deraadt Exp $ */
+/* $OpenBSD: expand.c,v 1.9 2003/04/19 17:22:29 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -39,7 +39,7 @@ static char RCSid[] =
"$From: expand.c,v 6.18 1998/03/24 00:37:10 michaelc Exp $";
#else
static char RCSid[] =
-"$OpenBSD: expand.c,v 1.8 2003/04/05 20:31:58 deraadt Exp $";
+"$OpenBSD: expand.c,v 1.9 2003/04/19 17:22:29 millert Exp $";
#endif
static char sccsid[] = "@(#)expand.c 5.2 (Berkeley) 3/28/86";
@@ -144,7 +144,7 @@ expand(list, wh) /* quote in list->n_name */
which = wh;
path = tpathp = pathp = pathbuf;
*pathp = CNULL;
- lastpathp = &path[sizeof pathbuf - 2];
+ lastpathp = &pathbuf[sizeof pathbuf - 2];
tilde = "";
eargc = 0;
eargv = sortbase = argvbuf;
@@ -292,8 +292,9 @@ void expstr(s)
if (pw == NULL || strcmp(pw->pw_name,
(char *)ebuf+1) != 0) {
if ((pw = getpwnam((char *)ebuf+1)) == NULL) {
- strcat((char *)ebuf,
- ": unknown user name");
+ strlcat((char *)ebuf,
+ ": unknown user name",
+ sizeof(ebuf));
yyerror((char *)ebuf+1);
return;
}
@@ -399,7 +400,8 @@ void matchdir(pattern) /* quote in pattern */
if (which & E_TILDE)
Cat((u_char *)path, (u_char *)dp->d_name);
else {
- (void) strcpy(pathp, dp->d_name);
+ (void) strlcpy(pathp, dp->d_name,
+ lastpathp - pathp + 2);
Cat((u_char *)tilde, (u_char *)tpathp);
*pathp = CNULL;
}
@@ -410,8 +412,8 @@ void matchdir(pattern) /* quote in pattern */
patherr1:
closedir(dirp);
patherr2:
- (void) strcat(path, ": ");
- (void) strcat(path, SYSERR);
+ (void) strlcat(path, ": ", lastpathp - path + 2);
+ (void) strlcat(path, SYSERR, lastpathp - path + 2);
yyerror(path);
}
@@ -478,7 +480,9 @@ pend:
doit:
savec = *pm;
*pm = 0;
- (void) strcpy((char *)lm, (char *)pl);
+ *lm = 0;
+ (void) strlcat((char *)restbuf, (char *)pl,
+ sizeof restbuf);
(void) strlcat((char *)restbuf, (char *)pe + 1,
sizeof restbuf);
*pm = savec;
diff --git a/usr.bin/rdist/message.c b/usr.bin/rdist/message.c
index 3dd1d5eaf90..a0cc941e2f9 100644
--- a/usr.bin/rdist/message.c
+++ b/usr.bin/rdist/message.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: message.c,v 1.12 2003/04/06 18:57:44 deraadt Exp $ */
+/* $OpenBSD: message.c,v 1.13 2003/04/19 17:22:29 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.12 2003/04/06 18:57:44 deraadt Exp $";
+"$OpenBSD: message.c,v 1.13 2003/04/19 17:22:29 millert Exp $";
#endif
static char sccsid[] = "@(#)common.c";
@@ -59,7 +59,6 @@ static char copyright[] =
int debug = 0; /* Debugging level */
int nerrs = 0; /* Number of errors */
-char *tempfile = NULL; /* Name of temporary file */
/*
* Message Types
@@ -455,6 +454,8 @@ static void msgsendnotify(msgfac, mtype, flags, msgbuf)
int flags;
char *msgbuf;
{
+ char *tempfile;
+
if (IS_ON(flags, MT_DEBUG))
return;
@@ -472,7 +473,7 @@ static void msgsendnotify(msgfac, mtype, flags, msgbuf)
*/
if ((cp = getenv("TMPDIR")) == NULL)
cp = _PATH_TMP;
- len = strlen(cp) + 1 + strlen(_RDIST_TMP) + 2;
+ len = strlen(cp) + 1 + sizeof(_RDIST_TMP);
tempfile = (char *) xmalloc(len);
(void) snprintf(tempfile, len, "%s/%s", cp, _RDIST_TMP);