diff options
-rw-r--r-- | bin/csh/csh.c | 31 | ||||
-rw-r--r-- | bin/csh/csh.h | 6 | ||||
-rw-r--r-- | bin/csh/dir.c | 28 | ||||
-rw-r--r-- | bin/csh/dol.c | 18 | ||||
-rw-r--r-- | bin/csh/exec.c | 35 | ||||
-rw-r--r-- | bin/csh/extern.h | 4 | ||||
-rw-r--r-- | bin/csh/file.c | 19 | ||||
-rw-r--r-- | bin/csh/glob.c | 18 | ||||
-rw-r--r-- | bin/csh/lex.c | 16 | ||||
-rw-r--r-- | bin/csh/proc.c | 8 | ||||
-rw-r--r-- | bin/csh/sem.c | 6 | ||||
-rw-r--r-- | bin/csh/set.c | 8 | ||||
-rw-r--r-- | bin/csh/str.c | 73 |
13 files changed, 175 insertions, 95 deletions
diff --git a/bin/csh/csh.c b/bin/csh/csh.c index d0149a8f48f..0bdd06737bd 100644 --- a/bin/csh/csh.c +++ b/bin/csh/csh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: csh.c,v 1.18 2002/06/09 05:47:27 todd Exp $ */ +/* $OpenBSD: csh.c,v 1.19 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: csh.c,v 1.14 1995/04/29 23:21:28 mycroft Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)csh.c 8.2 (Berkeley) 10/12/93"; #else -static char rcsid[] = "$OpenBSD: csh.c,v 1.18 2002/06/09 05:47:27 todd Exp $"; +static char rcsid[] = "$OpenBSD: csh.c,v 1.19 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -802,9 +802,9 @@ rechist() */ if ((shist = adrof(STRsavehist)) != NULL) { if (shist->vec[0][0] != '\0') - (void) Strcpy(hbuf, shist->vec[0]); + (void) Strlcpy(hbuf, shist->vec[0], sizeof hbuf/sizeof(Char)); else if ((shist = adrof(STRhistory)) && shist->vec[0][0] != '\0') - (void) Strcpy(hbuf, shist->vec[0]); + (void) Strlcpy(hbuf, shist->vec[0], sizeof hbuf/sizeof(Char)); else return; } @@ -812,8 +812,9 @@ rechist() return; if ((hfile = value(STRhistfile)) == STRNULL) { - hfile = Strcpy(buf, value(STRhome)); - (void) Strcat(buf, STRsldthist); + Strlcpy(buf, value(STRhome), sizeof buf/sizeof(Char)); + hfile = buf; + (void) Strlcat(buf, STRsldthist, sizeof buf/sizeof(Char)); } if ((fp = open(short2str(hfile), O_WRONLY | O_CREAT | O_TRUNC, @@ -1139,6 +1140,7 @@ dosource(v, t) register Char *f; bool hflg = 0; Char buf[BUFSIZ]; + char sbuf[BUFSIZ]; v++; if (*v && eq(*v, STRmh)) { @@ -1146,12 +1148,12 @@ dosource(v, t) stderror(ERR_NAME | ERR_HFLAG); hflg++; } - (void) Strcpy(buf, *v); + (void) Strlcpy(buf, *v, sizeof buf/sizeof(Char)); f = globone(buf, G_ERROR); - (void) strcpy((char *) buf, short2str(f)); + (void) strlcpy(sbuf, short2str(f), sizeof sbuf); xfree((ptr_t) f); - if (!srcfile((char *) buf, 0, hflg) && !hflg) - stderror(ERR_SYSTEM, (char *) buf, strerror(errno)); + if (!srcfile(sbuf, 0, hflg) && !hflg) + stderror(ERR_SYSTEM, sbuf, strerror(errno)); } /* @@ -1208,8 +1210,9 @@ mailchk() * We write the home directory of the user back there. */ int -gethdir(home) +gethdir(home, len) Char *home; + int len; { Char *h; struct passwd *pw; @@ -1219,7 +1222,8 @@ gethdir(home) */ if (*home == '\0') { if ((h = value(STRhome)) != NULL) { - (void) Strcpy(home, h); + if (Strlcpy(home, h, len) >= len) + return 1; return 0; } else @@ -1227,7 +1231,8 @@ gethdir(home) } if ((pw = getpwnam(short2str(home))) != NULL) { - (void) Strcpy(home, str2short(pw->pw_dir)); + if (Strlcpy(home, str2short(pw->pw_dir), len) >= len) + return 1; return 0; } else diff --git a/bin/csh/csh.h b/bin/csh/csh.h index a7029b2ef38..4ec357dc518 100644 --- a/bin/csh/csh.h +++ b/bin/csh/csh.h @@ -1,4 +1,4 @@ -/* $OpenBSD: csh.h,v 1.8 2002/02/16 21:27:06 millert Exp $ */ +/* $OpenBSD: csh.h,v 1.9 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: csh.h,v 1.9 1995/03/21 09:02:40 cgd Exp $ */ /*- @@ -490,8 +490,10 @@ Char HISTSUB; /* auto-substitute character */ #define Strchr(a, b) strchr(a, b) #define Strrchr(a, b) strrchr(a, b) #define Strcat(a, b) strcat(a, b) +#define Strlcat(a, b, l) strlcat(a, b, l) #define Strncat(a, b, c) strncat(a, b, c) #define Strcpy(a, b) strcpy(a, b) +#define Strlcpy(a, b, l) strlcpy(a, b, l) #define Strncpy(a, b, c) strncpy(a, b, c) #define Strlen(a) strlen(a) #define Strcmp(a, b) strcmp(a, b) @@ -510,8 +512,10 @@ Char HISTSUB; /* auto-substitute character */ #define Strchr(a, b) s_strchr(a, b) #define Strrchr(a, b) s_strrchr(a, b) #define Strcat(a, b) s_strcat(a, b) +#define Strlcat(a, b, l) s_strlcat(a, b, l) #define Strncat(a, b, c) s_strncat(a, b, c) #define Strcpy(a, b) s_strcpy(a, b) +#define Strlcpy(a, b, l) s_strlcpy(a, b, l) #define Strncpy(a, b, c) s_strncpy(a, b, c) #define Strlen(a) s_strlen(a) #define Strcmp(a, b) s_strcmp(a, b) diff --git a/bin/csh/dir.c b/bin/csh/dir.c index 64ad90d8754..1fd86717bbb 100644 --- a/bin/csh/dir.c +++ b/bin/csh/dir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.c,v 1.8 2002/08/12 00:42:56 aaron Exp $ */ +/* $OpenBSD: dir.c,v 1.9 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: dir.c,v 1.9 1995/03/21 09:02:42 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)dir.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: dir.c,v 1.8 2002/08/12 00:42:56 aaron Exp $"; +static char rcsid[] = "$OpenBSD: dir.c,v 1.9 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -284,10 +284,11 @@ dnormalize(cp) if (adrof(STRignore_symlinks)) { int dotdot = 0; Char *dp, *cwd; + size_t len; - cwd = (Char *) xmalloc((size_t) ((Strlen(dcwd->di_name) + 3) * - sizeof(Char))); - (void) Strcpy(cwd, dcwd->di_name); + len = (size_t) (Strlen(dcwd->di_name) + 3); + cwd = (Char *) xmalloc(len * sizeof(Char)); + (void) Strlcpy(cwd, dcwd->di_name, len); /* * Ignore . and count ..'s @@ -474,7 +475,7 @@ dfollow(cp) printd = 1; return dgoto(cp); } - (void) strcpy(ebuf, short2str(cp)); + (void) strlcpy(ebuf, short2str(cp), sizeof ebuf); xfree((ptr_t) cp); stderror(ERR_SYSTEM, ebuf, strerror(serrno)); return (NULL); @@ -527,7 +528,7 @@ dopushd(v, t) register Char *ccp; ccp = dfollow(*v); - dp = (struct directory *) xcalloc(sizeof(struct directory), 1); + dp = (struct directory *) xcalloc(1, sizeof(struct directory)); dp->di_name = ccp; dp->di_count = 0; dp->di_prev = dcwd; @@ -657,9 +658,9 @@ dcanon(cp, p) abort(); if (Strlen(p1) + Strlen(cp) + 1 >= MAXPATHLEN) abort(); - (void) Strcpy(tmpdir, p1); - (void) Strcat(tmpdir, STRslash); - (void) Strcat(tmpdir, cp); + (void) Strlcpy(tmpdir, p1, sizeof tmpdir/sizeof(Char)); + (void) Strlcat(tmpdir, STRslash, sizeof tmpdir/sizeof(Char)); + (void) Strlcat(tmpdir, cp, sizeof tmpdir/sizeof(Char)); xfree((ptr_t) cp); cp = p = Strsave(tmpdir); } @@ -705,7 +706,7 @@ dcanon(cp, p) if (sp != cp && !adrof(STRignore_symlinks) && (cc = readlink(short2str(cp), tlink, sizeof tlink-1)) >= 0) { - (void) Strcpy(link, str2short(tlink)); + (void) Strlcpy(link, str2short(tlink), sizeof link/sizeof(Char)); link[cc] = '\0'; if (slash) @@ -790,7 +791,7 @@ dcanon(cp, p) !adrof(STRignore_symlinks) && (cc = readlink(short2str(cp), tlink, sizeof tlink-1)) >= 0) { - (void) Strcpy(link, str2short(tlink)); + (void) Strlcpy(link, str2short(tlink), sizeof link/sizeof(Char)); link[cc] = '\0'; /* @@ -893,7 +894,8 @@ dcanon(cp, p) /* * Start comparing dev & ino backwards */ - p2 = Strcpy(link, cp); + Strlcpy(link, cp, sizeof link/sizeof(Char)); + p2 = link; for (sp = NULL; *p2 && stat(short2str(p2), &statbuf) != -1;) { if (statbuf.st_dev == home_dev && statbuf.st_ino == home_ino) { diff --git a/bin/csh/dol.c b/bin/csh/dol.c index 00567ea7c39..9e215b220c6 100644 --- a/bin/csh/dol.c +++ b/bin/csh/dol.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dol.c,v 1.10 2002/06/09 05:47:27 todd Exp $ */ +/* $OpenBSD: dol.c,v 1.11 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: dol.c,v 1.8 1995/09/27 00:38:38 jtc Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)dol.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: dol.c,v 1.10 2002/06/09 05:47:27 todd Exp $"; +static char rcsid[] = "$OpenBSD: dol.c,v 1.11 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -470,7 +470,7 @@ Dgetdol() break; case '*': - (void) Strcpy(name, STRargv); + (void) Strlcpy(name, STRargv, sizeof name/sizeof(Char)); vp = adrof(STRargv); subscr = -1; /* Prevent eating [...] */ break; @@ -729,12 +729,12 @@ setDolp(cp) do { dp = Strstr(cp, lhsub); if (dp) { - np = (Char *) xmalloc((size_t) - ((Strlen(cp) + 1 - lhlen + rhlen) * - sizeof(Char))); - (void) Strncpy(np, cp, dp - cp); - (void) Strcpy(np + (dp - cp), rhsub); - (void) Strcpy(np + (dp - cp) + rhlen, dp + lhlen); + size_t len = Strlen(cp) + 1 - lhlen + rhlen; + + np = (Char *) xmalloc(len * sizeof(Char)); + (void) Strlcpy(np, cp, len); + (void) Strlcat(np, rhsub, len); + (void) Strlcat(np, dp + lhlen, len); xfree((ptr_t) cp); dp = cp = np; diff --git a/bin/csh/exec.c b/bin/csh/exec.c index f7da9108d48..b97bb1ad5f1 100644 --- a/bin/csh/exec.c +++ b/bin/csh/exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.c,v 1.10 2002/06/09 05:47:27 todd Exp $ */ +/* $OpenBSD: exec.c,v 1.11 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: exec.c,v 1.9 1996/09/30 20:03:54 christos Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.3 (Berkeley) 5/23/95"; #else -static char rcsid[] = "$OpenBSD: exec.c,v 1.10 2002/06/09 05:47:27 todd Exp $"; +static char rcsid[] = "$OpenBSD: exec.c,v 1.11 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -103,7 +103,7 @@ static Char *justabs[] = {STRNULL, 0}; static void pexerr(void); static void texec(Char *, Char **); static int hashname(Char *); -static int tellmewhat(struct wordent *, Char *); +static int tellmewhat(struct wordent *, Char *, int len); static int executable(Char *, Char *, bool); static int iscommand(Char *); @@ -647,15 +647,16 @@ dowhich(v, c) } else { lex[1].word = *v; - set(STRstatus, Strsave(tellmewhat(lex, NULL) ? STR0 : STR1)); + set(STRstatus, Strsave(tellmewhat(lex, NULL, 0) ? STR0 : STR1)); } } } static int -tellmewhat(lexp, str) +tellmewhat(lexp, str, len) struct wordent *lexp; Char *str; + int len; { register int i; register struct biltins *bptr; @@ -700,13 +701,13 @@ tellmewhat(lexp, str) for (bptr = bfunc; bptr < &bfunc[nbfunc]; bptr++) { if (eq(sp->word, str2short(bptr->bname))) { if (str == NULL) { - if (aliased) - prlex(cshout, lexp); - (void) fprintf(cshout, "%s: shell built-in command.\n", + if (aliased) + prlex(cshout, lexp); + (void) fprintf(cshout, "%s: shell built-in command.\n", vis_str(sp->word)); } else - (void) Strcpy(str, sp->word); + (void) Strlcpy(str, sp->word, len/sizeof(Char)); sp->word = s0; /* we save and then restore this */ return 1; } @@ -737,26 +738,26 @@ tellmewhat(lexp, str) prlex(cshout, lexp); } else { - s1 = Strspl(*pv, STRslash); - sp->word = Strspl(s1, sp->word); - xfree((ptr_t) s1); + s1 = Strspl(*pv, STRslash); + sp->word = Strspl(s1, sp->word); + xfree((ptr_t) s1); if (str == NULL) prlex(cshout, lexp); else - (void) Strcpy(str, sp->word); - xfree((ptr_t) sp->word); - } + (void) Strlcpy(str, sp->word, len/sizeof(Char)); + xfree((ptr_t) sp->word); + } found = 1; } else { if (str == NULL) { - if (aliased) + if (aliased) prlex(cshout, lexp); (void) fprintf(csherr, "%s: Command not found.\n", vis_str(sp->word)); } else - (void) Strcpy(str, sp->word); + (void) Strlcpy(str, sp->word, len/sizeof(Char)); found = 0; } sp->word = s0; /* we save and then restore this */ diff --git a/bin/csh/extern.h b/bin/csh/extern.h index 6b161488209..f5b7f7d4a48 100644 --- a/bin/csh/extern.h +++ b/bin/csh/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.5 2002/02/17 19:42:18 millert Exp $ */ +/* $OpenBSD: extern.h,v 1.6 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: extern.h,v 1.8 1996/10/31 23:50:54 christos Exp $ */ /*- @@ -41,7 +41,7 @@ /* * csh.c */ -int gethdir(Char *); +int gethdir(Char *, int); void dosource(Char **, struct command *); void exitstat(void); void goodbye(void); diff --git a/bin/csh/file.c b/bin/csh/file.c index 422b2700fd1..585da7c9b71 100644 --- a/bin/csh/file.c +++ b/bin/csh/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.12 2002/07/24 19:53:50 millert Exp $ */ +/* $OpenBSD: file.c,v 1.13 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: file.c,v 1.11 1996/11/08 19:34:37 christos Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)file.c 8.2 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: file.c,v 1.12 2002/07/24 19:53:50 millert Exp $"; +static char rcsid[] = "$OpenBSD: file.c,v 1.13 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -222,7 +222,8 @@ filetype(dir, file) Char path[MAXPATHLEN]; struct stat statb; - catn(Strcpy(path, dir), file, sizeof(path) / sizeof(Char)); + Strlcpy(path, dir, sizeof path/sizeof(Char)); + catn(path, file, sizeof(path) / sizeof(Char)); if (lstat(short2str(path), &statb) == 0) { switch (statb.st_mode & S_IFMT) { case S_IFDIR: @@ -301,21 +302,23 @@ tilde(new, old) register struct passwd *pw; static Char person[40]; - if (old[0] != '~') - return (Strcpy(new, old)); + if (old[0] != '~') { + Strlcpy(new, old, MAXPATHLEN); + return new; + } for (p = person, o = &old[1]; *o && *o != '/'; *p++ = *o++) continue; *p = '\0'; if (person[0] == '\0') - (void) Strcpy(new, value(STRhome)); + (void) Strlcpy(new, value(STRhome), MAXPATHLEN); else { pw = getpwnam(short2str(person)); if (pw == NULL) return (NULL); - (void) Strcpy(new, str2short(pw->pw_dir)); + (void) Strlcpy(new, str2short(pw->pw_dir), MAXPATHLEN); } - (void) Strcat(new, o); + (void) Strlcat(new, o, MAXPATHLEN); return (new); } diff --git a/bin/csh/glob.c b/bin/csh/glob.c index d012450b43f..0837a4a259d 100644 --- a/bin/csh/glob.c +++ b/bin/csh/glob.c @@ -1,4 +1,4 @@ -/* $OpenBSD: glob.c,v 1.8 2002/06/09 05:47:27 todd Exp $ */ +/* $OpenBSD: glob.c,v 1.9 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: glob.c,v 1.10 1995/03/21 09:03:01 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)glob.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: glob.c,v 1.8 2002/06/09 05:47:27 todd Exp $"; +static char rcsid[] = "$OpenBSD: glob.c,v 1.9 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -110,7 +110,7 @@ globtilde(nv, s) *b++ = *s++) continue; *b = EOS; - if (gethdir(gstart)) { + if (gethdir(gstart, &gbuf[sizeof(gbuf)/sizeof(Char)] - gstart)) { blkfree(nv); if (*gstart) stderror(ERR_UNKUSER, vis_str(gstart)); @@ -195,8 +195,8 @@ globbrace(s, p, bl) Char savec = *pm; *pm = EOS; - (void) Strcpy(lm, pl); - (void) Strcat(gbuf, pe + 1); + (void) Strlcpy(lm, pl, &gbuf[sizeof(gbuf)/sizeof(Char)] - lm); + (void) Strlcat(gbuf, pe + 1, MAXPATHLEN); *pm = savec; *vl++ = Strsave(gbuf); len++; @@ -371,7 +371,8 @@ handleone(str, vl, action) str = Strspl(cp, *vlp); xfree((ptr_t) cp); } - while (*++vlp); + while (*++vlp) + ; blkfree(vl); break; case G_IGNORE: @@ -422,7 +423,8 @@ libglob(vl) } gflgs |= GLOB_APPEND; } - while (*++vl); + while (*++vl) + ; vl = (globv.gl_pathc == 0 || (magic && !match && !nonomatch)) ? NULL : blk2short(globv.gl_pathv); globfree(&globv); @@ -933,7 +935,7 @@ sortscmp(a, b) return (-1); #if defined(NLS) && !defined(NOSTRCOLL) - (void) strcpy(buf, short2str(*(Char **)a)); + (void) strlcpy(buf, short2str(*(Char **)a), sizeof buf); return ((int) strcoll(buf, short2str(*(Char **)b))); #else return ((int) Strcmp(*(Char **)a, *(Char **)b)); diff --git a/bin/csh/lex.c b/bin/csh/lex.c index 84fbf766ee3..a87160b5f7a 100644 --- a/bin/csh/lex.c +++ b/bin/csh/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.7 2002/06/09 05:47:27 todd Exp $ */ +/* $OpenBSD: lex.c,v 1.8 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: lex.c,v 1.9 1995/09/27 00:38:46 jtc Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)lex.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: lex.c,v 1.7 2002/06/09 05:47:27 todd Exp $"; +static char rcsid[] = "$OpenBSD: lex.c,v 1.8 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -635,10 +635,10 @@ addla(cp) return; } if (lap) - (void) Strcpy(buf, lap); - (void) Strcpy(labuf, cp); + (void) Strlcpy(buf, lap, sizeof buf/sizeof(Char)); + (void) Strlcpy(labuf, cp, sizeof labuf/sizeof(Char)); if (lap) - (void) Strcat(labuf, buf); + (void) Strlcat(labuf, buf, sizeof labuf/sizeof(Char)); lap = labuf; } @@ -770,7 +770,7 @@ getsub(en) seterror(ERR_NOSUBST); return (en); } - (void) Strcpy(lhsb, slhs); + (void) Strlcpy(lhsb, slhs, sizeof(lhsb)/sizeof(Char)); break; #ifdef notdef @@ -816,7 +816,7 @@ getsub(en) return (en); } cp = rhsb; - (void) Strcpy(orhsb, cp); + (void) Strlcpy(orhsb, cp, sizeof(orhsb)/sizeof(Char)); for (;;) { c = getC(0); if (c == '\n') { @@ -855,7 +855,7 @@ getsub(en) seterror(ERR_BADBANGMOD, c); return (en); } - (void) Strcpy(slhs, lhsb); + (void) Strlcpy(slhs, lhsb, sizeof(slhs)/sizeof(Char)); if (exclc) en = dosub(sc, en, global); } diff --git a/bin/csh/proc.c b/bin/csh/proc.c index e4dbfaa0d7c..4c69a71bc10 100644 --- a/bin/csh/proc.c +++ b/bin/csh/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.15 2002/02/19 19:39:35 millert Exp $ */ +/* $OpenBSD: proc.c,v 1.16 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: proc.c,v 1.9 1995/04/29 23:21:33 mycroft Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)proc.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: proc.c,v 1.15 2002/02/19 19:39:35 millert Exp $"; +static char rcsid[] = "$OpenBSD: proc.c,v 1.16 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -600,12 +600,12 @@ pads(cp) if (cmdlen >= PMAXLEN) return; if (cmdlen + i >= PMAXLEN) { - (void) Strcpy(cmdp, STRsp3dots); + (void) Strlcpy(cmdp, STRsp3dots, PMAXLEN - i); /* XXX? */ cmdlen = PMAXLEN; cmdp += 4; return; } - (void) Strcpy(cmdp, cp); + (void) Strlcpy(cmdp, cp, PMAXLEN); cmdp += i; cmdlen += i; } diff --git a/bin/csh/sem.c b/bin/csh/sem.c index 29e7bcd3165..d23ce8f68dc 100644 --- a/bin/csh/sem.c +++ b/bin/csh/sem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sem.c,v 1.11 2002/02/19 19:39:35 millert Exp $ */ +/* $OpenBSD: sem.c,v 1.12 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: sem.c,v 1.9 1995/09/27 00:38:50 jtc Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)sem.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: sem.c,v 1.11 2002/02/19 19:39:35 millert Exp $"; +static char rcsid[] = "$OpenBSD: sem.c,v 1.12 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -91,7 +91,7 @@ execute(t, wanttty, pipein, pipeout) case NODE_COMMAND: if ((t->t_dcom[0][0] & (QUOTE | TRIM)) == QUOTE) - (void) Strcpy(t->t_dcom[0], t->t_dcom[0] + 1); + (void) Strcpy(t->t_dcom[0], t->t_dcom[0] + 1); /* safe */ if ((t->t_dflg & F_REPEAT) == 0) Dfix(t); /* $ " ' \ */ if (t->t_dcom[0] == 0) diff --git a/bin/csh/set.c b/bin/csh/set.c index 8d04fa3bf45..ad6864c79f9 100644 --- a/bin/csh/set.c +++ b/bin/csh/set.c @@ -1,4 +1,4 @@ -/* $OpenBSD: set.c,v 1.7 2002/02/19 19:39:35 millert Exp $ */ +/* $OpenBSD: set.c,v 1.8 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: set.c,v 1.8 1995/03/21 18:35:52 mycroft Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)set.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: set.c,v 1.7 2002/02/19 19:39:35 millert Exp $"; +static char rcsid[] = "$OpenBSD: set.c,v 1.8 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -665,10 +665,10 @@ exportpath(val) "Warning: ridiculously long PATH truncated\n"); break; } - (void) Strcat(exppath, *val++); + (void) Strlcat(exppath, *val++, sizeof exppath/sizeof(Char)); if (*val == 0 || eq(*val, STRRparen)) break; - (void) Strcat(exppath, STRcolon); + (void) Strlcat(exppath, STRcolon, sizeof exppath/sizeof(Char)); } Setenv(STRPATH, exppath); } diff --git a/bin/csh/str.c b/bin/csh/str.c index 7bbc8bf5ca3..bab76c9c89a 100644 --- a/bin/csh/str.c +++ b/bin/csh/str.c @@ -1,4 +1,4 @@ -/* $OpenBSD: str.c,v 1.6 2002/06/09 05:47:27 todd Exp $ */ +/* $OpenBSD: str.c,v 1.7 2003/01/08 06:54:16 deraadt Exp $ */ /* $NetBSD: str.c,v 1.6 1995/03/21 09:03:24 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)str.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: str.c,v 1.6 2002/06/09 05:47:27 todd Exp $"; +static char rcsid[] = "$OpenBSD: str.c,v 1.7 2003/01/08 06:54:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -173,6 +173,66 @@ s_strcpy(dst, src) return (sdst); } +size_t +s_strlcpy(dst, src, siz) + Char *dst; + const Char *src; + size_t siz; +{ + register Char *d = dst; + register const Char *s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +size_t +s_strlcat(dst, src, siz) + Char *dst; + const Char *src; + size_t siz; +{ + register Char *d = dst; + register const Char *s = src; + register size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + s_strlen((Char *)s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} + Char * s_strncpy(dst, src, n) register Char *dst, *src; @@ -190,7 +250,8 @@ s_strncpy(dst, src, n) *dst++ = '\0'; return(sdst); } - while (--n != 0); + while (--n != 0) + ; return (sdst); } @@ -246,7 +307,8 @@ s_strchr(str, ch) do if (*str == ch) return (str); - while (*str++); + while (*str++) + ; return (NULL); } @@ -261,7 +323,8 @@ s_strrchr(str, ch) do if (*str == ch) rstr = str; - while (*str++); + while (*str++) + ; return (rstr); } |