diff options
author | 2006-12-06 04:59:58 +0000 | |
---|---|---|
committer | 2006-12-06 04:59:58 +0000 | |
commit | fda7d9c15e3f8785453d7514999e88c1518c8e78 (patch) | |
tree | 9dd9acbae983390152396e66da4b202152d65027 | |
parent | shorter url. (diff) | |
download | wireguard-openbsd-fda7d9c15e3f8785453d7514999e88c1518c8e78.tar.xz wireguard-openbsd-fda7d9c15e3f8785453d7514999e88c1518c8e78.zip |
Don't access buf[strlen(buf) - 1] for zero-length strings.
OK jaredy@.
-rw-r--r-- | usr.bin/infocmp/infocmp.c | 8 | ||||
-rw-r--r-- | usr.bin/less/filename.c | 3 | ||||
-rw-r--r-- | usr.bin/lex/initscan.c | 9 | ||||
-rw-r--r-- | usr.bin/lex/scan.l | 7 | ||||
-rw-r--r-- | usr.bin/sectok/cyberflex.c | 8 | ||||
-rw-r--r-- | usr.bin/sort/tmp.c | 6 | ||||
-rw-r--r-- | usr.sbin/config/misc.c | 7 | ||||
-rw-r--r-- | usr.sbin/config/mkmakefile.c | 6 |
8 files changed, 35 insertions, 19 deletions
diff --git a/usr.bin/infocmp/infocmp.c b/usr.bin/infocmp/infocmp.c index 12b5bca3628..d4750f8bca3 100644 --- a/usr.bin/infocmp/infocmp.c +++ b/usr.bin/infocmp/infocmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: infocmp.c,v 1.17 2003/04/08 19:08:58 deraadt Exp $ */ +/* $OpenBSD: infocmp.c,v 1.18 2006/12/06 04:59:58 ray Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -630,7 +630,8 @@ analyze_string(const char *name, const char *cap, TERMTYPE * tp) (void) strlcat(buf2, ";", sizeof buf2); } while ((ep = strtok((char *) 0, ";"))); - buf2[strlen(buf2) - 1] = '\0'; + if (buf2[0] != '\0' && buf2[strlen(buf2) - 1] == ';') + buf2[strlen(buf2) - 1] = '\0'; expansion = buf2; } @@ -666,7 +667,8 @@ analyze_string(const char *name, const char *cap, TERMTYPE * tp) } while ((ep = strtok((char *) 0, ";"))); - buf2[strlen(buf2) - 1] = '\0'; + if (buf2[0] != '\0' && buf2[strlen(buf2) - 1] == ';') + buf2[strlen(buf2) - 1] = '\0'; expansion = buf2; } /* now check for scroll region reset */ diff --git a/usr.bin/less/filename.c b/usr.bin/less/filename.c index ede2c6e1cb9..1c499e99411 100644 --- a/usr.bin/less/filename.c +++ b/usr.bin/less/filename.c @@ -676,7 +676,8 @@ lglob(filename) /* * Overwrite the final trailing space with a null terminator. */ - gfilename[strlen(gfilename) - 1] = '\0'; + if (gfilename[0] != '\0' && gfilename[strlen(gfilename) - 1] == ' ') + gfilename[strlen(gfilename) - 1] = '\0'; GLOB_LIST_DONE(list); } #else diff --git a/usr.bin/lex/initscan.c b/usr.bin/lex/initscan.c index 328e8ef3ba1..bf6749210cb 100644 --- a/usr.bin/lex/initscan.c +++ b/usr.bin/lex/initscan.c @@ -1,10 +1,10 @@ -/* $OpenBSD: initscan.c,v 1.10 2003/06/04 17:34:44 millert Exp $ */ +/* $OpenBSD: initscan.c,v 1.11 2006/12/06 05:03:29 ray Exp $ */ #line 2 "scan.c" /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /home/cvs/src/usr.bin/lex/Attic/initscan.c,v 1.10 2003/06/04 17:34:44 millert Exp $ + * $Header: /home/cvs/src/usr.bin/lex/Attic/initscan.c,v 1.11 2006/12/06 05:03:29 ray Exp $ */ #define FLEX_SCANNER @@ -1277,7 +1277,7 @@ char *yytext; * PURPOSE. */ -/* $Header: /home/cvs/src/usr.bin/lex/Attic/initscan.c,v 1.10 2003/06/04 17:34:44 millert Exp $ */ +/* $Header: /home/cvs/src/usr.bin/lex/Attic/initscan.c,v 1.11 2006/12/06 05:03:29 ray Exp $ */ #include "flexdef.h" #include "parse.h" @@ -2052,7 +2052,8 @@ YY_RULE_SETUP #line 279 "scan.l" { strlcpy( nmstr, yytext + 1, sizeof nmstr ); - nmstr[strlen( nmstr ) - 1] = '\0'; + if (nmstr[strlen(nmstr) - 1] == '"') + nmstr[strlen(nmstr) - 1] = '\0'; return NAME; } YY_BREAK diff --git a/usr.bin/lex/scan.l b/usr.bin/lex/scan.l index 4ea2957b8c7..39767ca2958 100644 --- a/usr.bin/lex/scan.l +++ b/usr.bin/lex/scan.l @@ -1,4 +1,4 @@ -/* $OpenBSD: scan.l,v 1.8 2003/06/04 17:34:44 millert Exp $ */ +/* $OpenBSD: scan.l,v 1.9 2006/12/06 05:03:29 ray Exp $ */ /* scan.l - scanner for flex input */ @@ -34,7 +34,7 @@ * PURPOSE. */ -/* $Header: /home/cvs/src/usr.bin/lex/scan.l,v 1.8 2003/06/04 17:34:44 millert Exp $ */ +/* $Header: /home/cvs/src/usr.bin/lex/scan.l,v 1.9 2006/12/06 05:03:29 ray Exp $ */ #include "flexdef.h" #include "parse.h" @@ -285,7 +285,8 @@ LEXOPT [aceknopr] \"[^"\n]*\" { strlcpy( nmstr, yytext + 1, sizeof nmstr); - nmstr[strlen( nmstr ) - 1] = '\0'; + if (nmstr[strlen(nmstr) - 1] == '"') + nmstr[strlen(nmstr) - 1] = '\0'; return NAME; } diff --git a/usr.bin/sectok/cyberflex.c b/usr.bin/sectok/cyberflex.c index 8cf1e9d0255..302e0908dcb 100644 --- a/usr.bin/sectok/cyberflex.c +++ b/usr.bin/sectok/cyberflex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cyberflex.c,v 1.26 2004/03/15 15:03:11 aaron Exp $ */ +/* $OpenBSD: cyberflex.c,v 1.27 2006/12/06 05:03:29 ray Exp $ */ /* * copyright 1999, 2000 @@ -480,6 +480,7 @@ acl(int argc, char *argv[]) } if (argc - optind < 1) { + usage: printf("usage: acl [-x] fid [principal: r1 r2 ...]\n"); return -1; } @@ -511,7 +512,10 @@ acl(int argc, char *argv[]) prin = argv[optind++]; /* strip trailing ':' */ - prin[strlen(prin) - 1] = '\0'; + if (prin[0] != '\0' && prin[strlen(prin) - 1] == ':') + prin[strlen(prin) - 1] = '\0'; + else + goto usage; /* Find principal */ for (prno = 0; prno < 8; prno++) diff --git a/usr.bin/sort/tmp.c b/usr.bin/sort/tmp.c index 6e13b84ab80..c9a4471da6d 100644 --- a/usr.bin/sort/tmp.c +++ b/usr.bin/sort/tmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmp.c,v 1.6 2003/06/10 22:20:51 deraadt Exp $ */ +/* $OpenBSD: tmp.c,v 1.7 2006/12/06 05:03:29 ray Exp $ */ /*- * Copyright (c) 1993 @@ -36,7 +36,7 @@ #if 0 static char sccsid[] = "@(#)tmp.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: tmp.c,v 1.6 2003/06/10 22:20:51 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: tmp.c,v 1.7 2006/12/06 05:03:29 ray Exp $"; #endif #endif /* not lint */ @@ -65,6 +65,8 @@ ftmp(void) char pathb[PATH_MAX], *path; path = pathb; + if (tmpdir[0] == '\0') + errx(2, "invalid temporary directory: \"\""); (void)snprintf(path, sizeof(pathb), "%s%s%s", tmpdir, (tmpdir[strlen(tmpdir)-1] != '/') ? "/" : "", _NAME_TMP); diff --git a/usr.sbin/config/misc.c b/usr.sbin/config/misc.c index a6389b6a3dd..da9c9f69b48 100644 --- a/usr.sbin/config/misc.c +++ b/usr.sbin/config/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.5 2005/04/28 22:28:00 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.6 2006/12/06 05:05:16 ray Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -26,7 +26,7 @@ */ #ifndef LINT -static char rcsid[] = "$OpenBSD: misc.c,v 1.5 2005/04/28 22:28:00 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.6 2006/12/06 05:05:16 ray Exp $"; #endif #include <sys/types.h> @@ -48,7 +48,8 @@ ask_cmd(cmd_t *cmd) /* Get input */ if (fgets(lbuf, sizeof lbuf, stdin) == NULL) errx(1, "eof"); - lbuf[strlen(lbuf)-1] = '\0'; + if ((cp = strchr(lbuf, '\n')) != NULL) + *cp = '\0'; if (verbose) printf("%s\n", lbuf); diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c index 7d12f1113e5..b0079afaf8c 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkmakefile.c,v 1.20 2006/05/06 11:31:46 espie Exp $ */ +/* $OpenBSD: mkmakefile.c,v 1.21 2006/12/06 05:05:16 ray Exp $ */ /* $NetBSD: mkmakefile.c,v 1.34 1997/02/02 21:12:36 thorpej Exp $ */ /* @@ -391,6 +391,10 @@ emitrules1(FILE *fp, const char *suffix, const char *rule_prefix, int ruleindex) return (1); if ((cp = fi->fi_mkrule[ruleindex]) == NULL) { cp = rule_prefix; + if (fpath[0] == '\0') { + errno = ENOENT; + return (1); + } ch = fpath[strlen(fpath) - 1]; if (islower(ch)) ch = toupper(ch); |