diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-05 20:31:59 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-05 20:31:59 +0000 |
commit | a30a19e6bb8e1cd59f6c8994d4be6856c7f06209 (patch) | |
tree | 75b9e4bf6b5fa6143d827012d0e0f8e8ec615832 /usr.bin | |
parent | d3a24c7fdcc3cdc9bdd398b0050e46b32597dcdf (diff) |
strings; ok miod ho krw
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rdist/client.c | 18 | ||||
-rw-r--r-- | usr.bin/rdist/common.c | 20 | ||||
-rw-r--r-- | usr.bin/rdist/distopt.c | 20 | ||||
-rw-r--r-- | usr.bin/rdist/docmd.c | 12 | ||||
-rw-r--r-- | usr.bin/rdist/expand.c | 7 | ||||
-rw-r--r-- | usr.bin/rdist/message.c | 52 | ||||
-rw-r--r-- | usr.bin/rdist/rdist.c | 17 | ||||
-rw-r--r-- | usr.bin/rdistd/filesys-os.c | 7 | ||||
-rw-r--r-- | usr.bin/rdistd/filesys.c | 12 | ||||
-rw-r--r-- | usr.bin/rdistd/server.c | 34 |
10 files changed, 107 insertions, 92 deletions
diff --git a/usr.bin/rdist/client.c b/usr.bin/rdist/client.c index 2b2883b3aa0..472a068ff60 100644 --- a/usr.bin/rdist/client.c +++ b/usr.bin/rdist/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.13 2001/11/19 19:02:15 mpech Exp $ */ +/* $OpenBSD: client.c,v 1.14 2003/04/05 20:31:58 deraadt 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.13 2001/11/19 19:02:15 mpech Exp $"; +"$OpenBSD: client.c,v 1.14 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)client.c"; @@ -109,7 +109,7 @@ char *remfilename(src, dest, path, rname, destdir) if (path && *path) { cp = strrchr(path, '/'); if (cp == NULL) - (void) sprintf(buff, "%s/%s", dest, path); + (void) snprintf(buff, sizeof buff, "%s/%s", dest, path); else { srclen = strlen(src); pathlen = strlen(path); @@ -127,9 +127,11 @@ char *remfilename(src, dest, path, rname, destdir) } } if ((*cp != '/') && *cp) - (void) sprintf(buff, "%s/%s", dest, cp); + (void) snprintf(buff, sizeof buff, + "%s/%s", dest, cp); else - (void) sprintf(buff, "%s%s", dest, cp); + (void) snprintf(buff, sizeof buff, + "%s%s", dest, cp); } } else strcpy(lname, dest); @@ -690,7 +692,7 @@ static int sendlink(rname, opts, stb, user, group, destdir) error("%s: readlink failed", target); err(); } - (void) sprintf(tbuf, "%.*s", (int) stb->st_size, lbuf); + (void) snprintf(tbuf, sizeof tbuf, "%.*s", (int) stb->st_size, lbuf); (void) sendcmd(C_NONE, "%s\n", tbuf); if (n != stb->st_size) { @@ -1205,7 +1207,7 @@ extern int install(src, dest, ddir, destdir, opts) char *cp; cp = getondistoptlist(opts); - (void) sprintf(buff, "%s%s%s %s %s", + (void) snprintf(buff, sizeof buff, "%s%s%s %s %s", IS_ON(opts, DO_VERIFY) ? "verify" : "install", (cp) ? " -o" : "", (cp) ? cp : "", src, dest); @@ -1264,7 +1266,7 @@ extern int install(src, dest, ddir, destdir, opts) * hardlink info. */ if (destdir || (src && dest && strcmp(src, dest))) { - (void) strcpy(destcopy, dest); + (void) strlcpy(destcopy, dest, sizeof destcopy); Tdest = destcopy; } diff --git a/usr.bin/rdist/common.c b/usr.bin/rdist/common.c index d4e72c20cb9..2309216a1dc 100644 --- a/usr.bin/rdist/common.c +++ b/usr.bin/rdist/common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: common.c,v 1.16 2002/06/23 03:07:22 deraadt Exp $ */ +/* $OpenBSD: common.c,v 1.17 2003/04/05 20:31:58 deraadt 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.16 2002/06/23 03:07:22 deraadt Exp $"; +"$OpenBSD: common.c,v 1.17 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)common.c"; @@ -481,7 +481,7 @@ extern int remline(buffer, space, doclean) if (debug) { static char mbuf[BUFSIZ]; - (void) sprintf(mbuf, + (void) snprintf(mbuf, sizeof mbuf, "<<< Cmd = %c (\\%3.3o) Msg = \"%s\"", buffer[0], buffer[0], buffer + 1); @@ -552,7 +552,7 @@ extern char *getusername(uid, file, opts) * do the opts check. */ if (IS_ON(opts, DO_NUMCHKOWNER)) { - (void) sprintf(buf, ":%u", uid); + (void) snprintf(buf, sizeof buf, ":%u", uid); return(buf); } @@ -567,9 +567,9 @@ extern char *getusername(uid, file, opts) if ((pwd = getpwuid(uid)) == NULL) { message(MT_WARNING, "%s: No password entry for uid %u", file, uid); - (void) sprintf(buf, ":%u", uid); + (void) snprintf(buf, sizeof buf, ":%u", uid); } else - (void) strcpy(buf, pwd->pw_name); + (void) strlcpy(buf, pwd->pw_name, sizeof buf); return(buf); } @@ -591,7 +591,7 @@ extern char *getgroupname(gid, file, opts) * do the opts check. */ if (IS_ON(opts, DO_NUMCHKGROUP)) { - (void) sprintf(buf, ":%u", gid); + (void) snprintf(buf, sizeof buf, ":%u", gid); return(buf); } @@ -605,9 +605,9 @@ extern char *getgroupname(gid, file, opts) if ((grp = (struct group *)getgrgid(gid)) == NULL) { message(MT_WARNING, "%s: No name for group %u", file, gid); - (void) sprintf(buf, ":%u", gid); + (void) snprintf(buf, sizeof buf, ":%u", gid); } else - (void) strcpy(buf, grp->gr_name); + (void) strlcpy(buf, grp->gr_name, sizeof buf); return(buf); } @@ -805,7 +805,7 @@ extern char *getversion() { static char buff[BUFSIZ]; - (void) sprintf(buff, + (void) snprintf(buff, sizeof buff, "Version %s.%d (%s) - Protocol Version %d, Release %s, Patch level %d", DISTVERSION, PATCHLEVEL, DISTSTATUS, VERSION, DISTVERSION, PATCHLEVEL); diff --git a/usr.bin/rdist/distopt.c b/usr.bin/rdist/distopt.c index d052b5865f1..ff05900078d 100644 --- a/usr.bin/rdist/distopt.c +++ b/usr.bin/rdist/distopt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: distopt.c,v 1.6 2001/11/19 19:02:15 mpech Exp $ */ +/* $OpenBSD: distopt.c,v 1.7 2003/04/05 20:31:58 deraadt 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.6 2001/11/19 19:02:15 mpech Exp $"; +"$OpenBSD: distopt.c,v 1.7 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)distopt.c"; @@ -154,10 +154,12 @@ extern char *getdistoptlist() for (i = 0, buf[0] = CNULL; distoptinfo[i].do_name; ++i) { if (buf[0] == CNULL) - (void) strcpy(buf, distoptinfo[i].do_name); + (void) strlcpy(buf, distoptinfo[i].do_name, + sizeof buf); else { - (void) strcat(buf, ","); - (void) strcat(buf, distoptinfo[i].do_name); + (void) strlcat(buf, ",", sizeof buf); + (void) strlcat(buf, distoptinfo[i].do_name, + sizeof buf); } } @@ -179,10 +181,12 @@ extern char *getondistoptlist(opts) continue; if (buf[0] == CNULL) - (void) strcpy(buf, distoptinfo[i].do_name); + (void) strlcpy(buf, distoptinfo[i].do_name, + sizeof buf); else { - (void) strcat(buf, ","); - (void) strcat(buf, distoptinfo[i].do_name); + (void) strlcat(buf, ",", sizeof buf); + (void) strlcat(buf, distoptinfo[i].do_name, + sizeof buf); } } diff --git a/usr.bin/rdist/docmd.c b/usr.bin/rdist/docmd.c index f9f470e1ee2..55c3a2ab32b 100644 --- a/usr.bin/rdist/docmd.c +++ b/usr.bin/rdist/docmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: docmd.c,v 1.11 2002/06/12 06:07:16 mpech Exp $ */ +/* $OpenBSD: docmd.c,v 1.12 2003/04/05 20:31:58 deraadt 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.11 2002/06/12 06:07:16 mpech Exp $"; +"$OpenBSD: docmd.c,v 1.12 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)docmd.c 5.1 (Berkeley) 6/6/85"; @@ -143,7 +143,7 @@ static void notify(rhost, to, lmod) * Set IFS to avoid possible security problem with users * setting "IFS=/". */ - (void) sprintf(buf, "IFS=\" \t\"; export IFS; %s -oi -t", + (void) snprintf(buf, sizeof buf, "IFS=\" \t\"; export IFS; %s -oi -t", _PATH_SENDMAIL); pf = popen(buf, "w"); if (pf == NULL) { @@ -354,7 +354,7 @@ static int makeconn(rhost) if (!IS_ON(options, DO_QUIET)) message(MT_VERBOSE, "updating host %s", rhost); - (void) sprintf(buf, "%.*s -S", sizeof(buf)-5, path_rdistd); + (void) snprintf(buf, sizeof buf, "%.*s -S", sizeof(buf)-5, path_rdistd); if ((rem_r = rem_w = remotecmd(rhost, locuser, ruser, buf)) < 0) return(0); @@ -717,7 +717,7 @@ static void cmptime(name, sbcmds, env) continue; if (sc->sc_args != NULL && !inlist(sc->sc_args, name)) continue; - (void) sprintf(buf, "%s=%s;%s", + (void) snprintf(buf, sizeof buf, "%s=%s;%s", E_LOCFILE, name, sc->sc_name); message(MT_CHANGE, "special \"%s\"", buf); if (*env) { @@ -769,7 +769,7 @@ static void dodcolon(cmd, filev) for (sc = sbcmds; sc != NULL; sc = sc->sc_next) { if (sc->sc_type == CMDSPECIAL) { env = (char *) xmalloc(sizeof(E_FILES) + 3); - (void) sprintf(env, "%s='", E_FILES); + (void) snprintf(env, sizeof(E_FILES) + 3, "%s='", E_FILES); break; } } diff --git a/usr.bin/rdist/expand.c b/usr.bin/rdist/expand.c index cc6155e53e1..1eade9335aa 100644 --- a/usr.bin/rdist/expand.c +++ b/usr.bin/rdist/expand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expand.c,v 1.7 2001/11/19 19:02:15 mpech Exp $ */ +/* $OpenBSD: expand.c,v 1.8 2003/04/05 20:31:58 deraadt 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.7 2001/11/19 19:02:15 mpech Exp $"; +"$OpenBSD: expand.c,v 1.8 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)expand.c 5.2 (Berkeley) 3/28/86"; @@ -479,7 +479,8 @@ doit: savec = *pm; *pm = 0; (void) strcpy((char *)lm, (char *)pl); - (void) strcat((char *)restbuf, (char *)pe + 1); + (void) strlcat((char *)restbuf, (char *)pe + 1, + sizeof restbuf); *pm = savec; if (s == 0) { spathp = pathp; diff --git a/usr.bin/rdist/message.c b/usr.bin/rdist/message.c index 5fd998aa994..ed886218c23 100644 --- a/usr.bin/rdist/message.c +++ b/usr.bin/rdist/message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: message.c,v 1.10 2001/11/19 19:02:15 mpech Exp $ */ +/* $OpenBSD: message.c,v 1.11 2003/04/05 20:31:58 deraadt 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.10 2001/11/19 19:02:15 mpech Exp $"; +"$OpenBSD: message.c,v 1.11 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)common.c"; @@ -279,7 +279,7 @@ extern char *msgparseopts(msgstr, doset) return("NULL message string"); /* strtok() is harmful */ - (void) strcpy(msgbuf, msgstr); + (void) strlcpy(msgbuf, msgstr, sizeof msgbuf); /* * Each <facility>=<types> list is separated by ":". @@ -464,15 +464,16 @@ static void msgsendnotify(msgfac, mtype, flags, msgbuf) char *cp; int fd; char *getenv(); + size_t len; /* * Create and open a new temporary file */ if ((cp = getenv("TMPDIR")) == NULL) cp = _PATH_TMP; - tempfile = (char *) xmalloc(strlen(cp) + 1 + - strlen(_RDIST_TMP) + 2); - (void) sprintf(tempfile, "%s/%s", cp, _RDIST_TMP); + len = strlen(cp) + 1 + strlen(_RDIST_TMP) + 2; + tempfile = (char *) xmalloc(len); + (void) snprintf(tempfile, len, "%s/%s", cp, _RDIST_TMP); msgfac->mf_filename = tempfile; if ((fd = mkstemp(msgfac->mf_filename)) == -1 || @@ -531,11 +532,12 @@ static void _message(flags, msgbuf) checkhostname(); if (strncmp(currenthost, msgbuf, strlen(currenthost)) == 0) - (void) strcpy(mbuf, msgbuf); + (void) strlcpy(mbuf, msgbuf, sizeof mbuf); else - (void) sprintf(mbuf, "%s: %s", currenthost, msgbuf); + (void) snprintf(mbuf, sizeof mbuf, + "%s: %s", currenthost, msgbuf); } else - (void) strcpy(mbuf, ""); + (void) strlcpy(mbuf, "", sizeof mbuf); /* * Special case for messages that only get @@ -596,7 +598,7 @@ extern void message(va_alist) fmt = (char *) va_arg(args, char *); va_end(args); - (void) vsprintf(buf, fmt, args); + (void) vsnprintf(buf, sizeof buf, fmt, args); _message(lvl, buf); } @@ -612,7 +614,7 @@ extern void message(int lvl, char *fmt, ...) va_list args; va_start(args, fmt); - (void) vsprintf(buf, fmt, args); + (void) vsnprintf(buf, sizeof buf, fmt, args); va_end(args); _message(lvl, buf); @@ -631,7 +633,7 @@ extern void message(lvl, fmt, a1, a2, a3, a4, a5) { static char buf[MSGBUFSIZ]; - (void) sprintf(buf, fmt, a1, a2, a3, a4, a5); + (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5); _message(lvl, buf); } @@ -665,7 +667,7 @@ extern void debugmsg(va_alist) fmt = (char *) va_arg(args, char *); va_end(args); - (void) vsprintf(buf, fmt, args); + (void) vsnprintf(buf, sizeof buf, fmt, args); _debugmsg(lvl, buf); } @@ -681,7 +683,7 @@ extern void debugmsg(int lvl, char *fmt, ...) va_list args; va_start(args, fmt); - (void) vsprintf(buf, fmt, args); + (void) vsnprintf(buf, sizeof buf, fmt, args); va_end(args); _debugmsg(lvl, buf); @@ -699,7 +701,7 @@ extern void debugmsg(lvl, fmt, a1, a2, a3, a4, a5) { static char buf[MSGBUFSIZ]; - (void) sprintf(buf, fmt, a1, a2, a3, a4, a5); + (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5); _debugmsg(lvl, buf); } @@ -718,9 +720,9 @@ static void _error(msg) if (msg) { if (isserver) - (void) sprintf(buf, "REMOTE ERROR: %s", msg); + (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg); else - (void) sprintf(buf, "LOCAL ERROR: %s", msg); + (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg); } _message(MT_NERROR, (buf[0]) ? buf : NULL); @@ -741,7 +743,7 @@ extern void error(va_alist) va_start(args); fmt = (char *) va_arg(args, char *); if (fmt) - (void) vsprintf(buf, fmt, args); + (void) vsnprintf(buf, sizeof buf, fmt, args); va_end(args); _error((buf[0]) ? buf : NULL); @@ -760,7 +762,7 @@ extern void error(char *fmt, ...) buf[0] = CNULL; va_start(args, fmt); if (fmt) - (void) vsprintf(buf, fmt, args); + (void) vsnprintf(buf, sizeof buf, fmt, args); va_end(args); _error((buf[0]) ? buf : NULL); @@ -779,7 +781,7 @@ extern void error(fmt, a1, a2, a3, a4, a5, a6) buf[0] = CNULL; if (fmt) - (void) sprintf(buf, fmt, a1, a2, a3, a4, a5, a6); + (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5, a6); _error((buf[0]) ? buf : NULL); } @@ -796,9 +798,9 @@ static void _fatalerr(msg) ++nerrs; if (isserver) - (void) sprintf(buf, "REMOTE ERROR: %s", msg); + (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg); else - (void) sprintf(buf, "LOCAL ERROR: %s", msg); + (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg); _message(MT_FERROR, buf); @@ -818,7 +820,7 @@ extern void fatalerr(va_alist) va_start(args); fmt = (char *) va_arg(args, char *); - (void) vsprintf(buf, fmt, args); + (void) vsnprintf(buf, sizeof buf, fmt, args); va_end(args); _fatalerr(buf); @@ -835,7 +837,7 @@ extern void fatalerr(char *fmt, ...) va_list args; va_start(args, fmt); - (void) vsprintf(buf, fmt, args); + (void) vsnprintf(buf, sizeof buf, fmt, args); va_end(args); _fatalerr(buf); @@ -852,7 +854,7 @@ extern void fatalerr(fmt, a1, a2, a3, a4, a5) { static char buf[MSGBUFSIZ]; - (void) sprintf(buf, fmt, a1, a2, a3, a4, a5); + (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5); _fatalerr(buf); } diff --git a/usr.bin/rdist/rdist.c b/usr.bin/rdist/rdist.c index 0edfbb5c9fb..d25c4ea6209 100644 --- a/usr.bin/rdist/rdist.c +++ b/usr.bin/rdist/rdist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdist.c,v 1.13 2002/05/09 19:19:33 millert Exp $ */ +/* $OpenBSD: rdist.c,v 1.14 2003/04/05 20:31:58 deraadt 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.13 2002/05/09 19:19:33 millert Exp $"; +"$OpenBSD: rdist.c,v 1.14 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)main.c 5.1 (Berkeley) 6/6/85"; @@ -451,24 +451,25 @@ extern char *getnlstr(nl) static char buf[16384]; int count = 0, len = 0; - (void) sprintf(buf, "("); + (void) snprintf(buf, sizeof buf, "("); while (nl != NULL) { if (nl->n_name == NULL) continue; len += strlen(nl->n_name) + 2; if (len >= sizeof(buf)) { - (void) strcpy(buf, - "getnlstr() Buffer not large enough"); + (void) strlcpy(buf, + "getnlstr() Buffer not large enough", + sizeof buf); return(buf); } ++count; - (void) strcat(buf, " "); - (void) strcat(buf, nl->n_name); + (void) strlcat(buf, " ", sizeof buf); + (void) strlcat(buf, nl->n_name, sizeof buf); nl = nl->n_next; } - (void) strcat(buf, " )"); + (void) strlcat(buf, " )", sizeof buf); return(buf); } diff --git a/usr.bin/rdistd/filesys-os.c b/usr.bin/rdistd/filesys-os.c index 490510c7154..449dd124f4d 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.6 1999/02/04 23:18:57 millert Exp $ */ +/* $OpenBSD: filesys-os.c,v 1.7 2003/04/05 20:31:58 deraadt 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.6 1999/02/04 23:18:57 millert Exp $"; +"$OpenBSD: filesys-os.c,v 1.7 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)filesys-os.c"; @@ -193,7 +193,8 @@ mntent_t *getmountent(fptr) mntstruct.me_flags |= MEFLAG_READONLY; #endif if (f_type_eq(mnt, MOUNT_NFS)) { - (void) sprintf(remote_dev, "%s", mnt->f_mntfromname); + (void) snprintf(remote_dev, sizeof remote_dev, + "%s", mnt->f_mntfromname); mntstruct.me_path = remote_dev; mntstruct.me_type = METYPE_NFS; } else { diff --git a/usr.bin/rdistd/filesys.c b/usr.bin/rdistd/filesys.c index 198cb3ffd5c..4ec9c0c56b2 100644 --- a/usr.bin/rdistd/filesys.c +++ b/usr.bin/rdistd/filesys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filesys.c,v 1.7 2001/11/19 19:02:15 mpech Exp $ */ +/* $OpenBSD: filesys.c,v 1.8 2003/04/05 20:31:58 deraadt Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -39,7 +39,7 @@ static char RCSid[] = "$From: filesys.c,v 6.24 1996/01/30 01:57:07 mcooper Exp $"; #else static char RCSid[] = -"$OpenBSD: filesys.c,v 1.7 2001/11/19 19:02:15 mpech Exp $"; +"$OpenBSD: filesys.c,v 1.8 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)filesys.c"; @@ -100,18 +100,18 @@ char *find_file(pathname, statbuf, isvalid) /* * Save for next time */ - (void) strcpy(last_pathname, pathname); + (void) strlcpy(last_pathname, pathname, sizeof last_pathname); if (*pathname == '/') - (void) strcpy(file, pathname); + (void) strlcpy(file, pathname, sizeof file); else { /* * Ensure we have a directory (".") in our path * so we have something to stat in case the file * does not exist. */ - (void) strcpy(file, "./"); - (void) strcat(file, pathname); + (void) strlcpy(file, "./", sizeof file); + (void) strlcat(file, pathname, sizeof file); } while (lstat(file, &filestat) != 0) { diff --git a/usr.bin/rdistd/server.c b/usr.bin/rdistd/server.c index 833cb29108b..e156b045e35 100644 --- a/usr.bin/rdistd/server.c +++ b/usr.bin/rdistd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.10 2001/11/19 19:02:15 mpech Exp $ */ +/* $OpenBSD: server.c,v 1.11 2003/04/05 20:31:58 deraadt 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.10 2001/11/19 19:02:15 mpech Exp $"; +"$OpenBSD: server.c,v 1.11 2003/04/05 20:31:58 deraadt Exp $"; #endif static char sccsid[] = "@(#)server.c 5.3 (Berkeley) 6/7/86"; @@ -221,7 +221,7 @@ static int fchog(fd, file, owner, group, mode) } else { uid = last_uid = pw->pw_uid; primegid = last_primegid = pw->pw_gid; - strcpy(last_owner, owner); + strlcpy(last_owner, owner, sizeof last_owner); } } else { uid = last_uid; @@ -253,7 +253,7 @@ static int fchog(fd, file, owner, group, mode) */ if ((gr = mygetgroup(group))) { last_gid = gid = gr->gr_gid; - strcpy(last_group, gr->gr_name); + strlcpy(last_group, gr->gr_name, sizeof last_group); } else { if (mode != -1 && IS_ON(mode, S_ISGID)) { message(MT_NOTICE, @@ -528,12 +528,12 @@ static void docmdspecial() if (env == NULL) { len = (2 * sizeof(E_FILES)) + strlen(cp) + 10; env = (char *) xmalloc(len); - (void) sprintf(env, "export %s;%s=%s", + (void) snprintf(env, len, "export %s;%s=%s", E_FILES, E_FILES, cp); } else { len = strlen(env); env = (char *) xrealloc(env, - len + strlen(cp) + 2); + len + strlen(cp) + 2); env[len] = CNULL; (void) strcat(env, ":"); (void) strcat(env, cp); @@ -710,7 +710,7 @@ static char *savetarget(file) return(NULL); } - (void) sprintf(savefile, "%s%s", file, SAVE_SUFFIX); + (void) snprintf(savefile, sizeof savefile, "%s%s", file, SAVE_SUFFIX); if (unlink(savefile) != 0 && errno != ENOENT) { message(MT_NOTICE, "%s: remove failed: %s", savefile, SYSERR); @@ -1045,7 +1045,8 @@ static void recvdir(opts, mode, owner, group) opts; if ((cp = getusername(stb.st_uid, target, o))) if (strcmp(owner, cp)) - (void) strcpy(lowner, cp); + (void) strlcpy(lowner, cp, + sizeof lowner); } if (!IS_ON(opts, DO_NOCHKGROUP) && group) { int o; @@ -1054,7 +1055,8 @@ static void recvdir(opts, mode, owner, group) opts; if ((cp = getgroupname(stb.st_gid, target, o))) if (strcmp(group, cp)) - (void) strcpy(lgroup, cp); + (void) strlcpy(lgroup, cp, + sizeof lgroup); } /* @@ -1065,11 +1067,13 @@ static void recvdir(opts, mode, owner, group) if (lowner[0] == CNULL && (cp = getusername(stb.st_uid, target, opts))) - (void) strcpy(lowner, cp); + (void) strlcpy(lowner, cp, + sizeof lowner); if (lgroup[0] == CNULL && (cp = getgroupname(stb.st_gid, target, opts))) - (void) strcpy(lgroup, cp); + (void) strlcpy(lgroup, cp, + sizeof lgroup); if (IS_ON(opts, DO_VERIFY)) message(MT_NOTICE, @@ -1469,12 +1473,12 @@ static void recvit(cmd, type) } file = strrchr(target, '/'); if (file == NULL) - (void) strcpy(new, tempname); + (void) strlcpy(new, tempname, sizeof new); else if (file == target) - (void) sprintf(new, "/%s", tempname); + (void) snprintf(new, sizeof new, "/%s", tempname); else { *file = CNULL; - (void) sprintf(new, "%s/%s", target, tempname); + (void) snprintf(new, sizeof new, "%s/%s", target, tempname); *file = '/'; } (void) mktemp(new); @@ -1596,7 +1600,7 @@ extern void server() (void) signal(SIGTERM, sighandler); (void) signal(SIGPIPE, sighandler); (void) umask(oumask = umask(0)); - (void) strcpy(tempname, _RDIST_TMP); + (void) strlcpy(tempname, _RDIST_TMP, sizeof tempname); if (fromhost) { message(MT_SYSLOG, "Startup for %s", fromhost); #if defined(SETARGS) |