diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-07-14 02:59:42 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-07-14 02:59:42 +0000 |
commit | c0f7498575f310c0d1bbc1e1042e7c60c8ddced0 (patch) | |
tree | d558ac13ab46aa7bc11f981b5f08c51ea2c63858 /usr.sbin/config | |
parent | 6715eae37fa352fa839662463dd316eae343b4de (diff) |
kill sprintf
Diffstat (limited to 'usr.sbin/config')
-rw-r--r-- | usr.sbin/config/main.c | 12 | ||||
-rw-r--r-- | usr.sbin/config/misc.c | 8 | ||||
-rw-r--r-- | usr.sbin/config/mkheaders.c | 23 | ||||
-rw-r--r-- | usr.sbin/config/ukcutil.c | 6 | ||||
-rw-r--r-- | usr.sbin/config/util.c | 7 |
5 files changed, 34 insertions, 22 deletions
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index f320a875158..54bb074d650 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.27 2002/06/14 21:35:01 todd Exp $ */ +/* $OpenBSD: main.c,v 1.28 2002/07/14 02:59:41 deraadt Exp $ */ /* $NetBSD: main.c,v 1.22 1997/02/02 21:12:33 thorpej Exp $ */ /* @@ -211,13 +211,15 @@ main(argc, argv) last_component = strrchr(conffile, '/'); last_component = (last_component) ? last_component + 1 : conffile; if (pflag) { - p = emalloc(strlen(last_component) + 17); - (void)sprintf(p, "../compile/%s.PROF", last_component); + int len = strlen(last_component) + 17; + p = emalloc(len); + (void)snprintf(p, len, "../compile/%s.PROF", last_component); (void)addmkoption(intern("PROF"), "-pg"); (void)addoption(intern("GPROF"), NULL); } else { - p = emalloc(strlen(last_component) + 13); - (void)sprintf(p, "../compile/%s", last_component); + int len = strlen(last_component) + 13; + p = emalloc(len); + (void)snprintf(p, len, "../compile/%s", last_component); } defbuilddir = (argc == 0) ? "." : p; diff --git a/usr.sbin/config/misc.c b/usr.sbin/config/misc.c index 316a8fc04cd..d8ba3948988 100644 --- a/usr.sbin/config/misc.c +++ b/usr.sbin/config/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.1 1999/10/04 20:00:51 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.2 2002/07/14 02:59:41 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -31,7 +31,7 @@ */ #ifndef LINT -static char rcsid[] = "$OpenBSD: misc.c,v 1.1 1999/10/04 20:00:51 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.2 2002/07/14 02:59:41 deraadt Exp $"; #endif #include <sys/types.h> @@ -59,9 +59,9 @@ ask_cmd(cmd) buf = &buf[strspn(buf, " \t")]; cp = &buf[strcspn(buf, " \t")]; *cp++ = '\0'; - strncpy(cmd->cmd, buf, 10); + strlcpy(cmd->cmd, buf, sizeof cmd->cmd); buf = &cp[strspn(cp, " \t")]; - strncpy(cmd->args, buf, 100); + strlcpy(cmd->args, buf, sizeof cmd->args); return (0); } diff --git a/usr.sbin/config/mkheaders.c b/usr.sbin/config/mkheaders.c index 8d067d0f999..7bc78f6601a 100644 --- a/usr.sbin/config/mkheaders.c +++ b/usr.sbin/config/mkheaders.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkheaders.c,v 1.13 2002/05/29 09:45:39 deraadt Exp $ */ +/* $OpenBSD: mkheaders.c,v 1.14 2002/07/14 02:59:41 deraadt Exp $ */ /* $NetBSD: mkheaders.c,v 1.12 1997/02/02 21:12:34 thorpej Exp $ */ /* @@ -132,22 +132,31 @@ emitopt(nv) { struct nvlist *option; char new_contents[BUFSIZ], buf[BUFSIZ]; - char fname[BUFSIZ], *p; + char fname[BUFSIZ], totlen; int nlines; FILE *fp; /* * Generate the new contents of the file. */ - p = new_contents; if ((option = ht_lookup(opttab, nv->nv_str)) == NULL) - p += sprintf(p, "/* option `%s' not defined */\n", + totlen = snprintf(new_contents, sizeof new_contents, + "/* option `%s' not defined */\n", nv->nv_str); else { - p += sprintf(p, "#define\t%s", option->nv_name); if (option->nv_str != NULL) - p += sprintf(p, "\t%s", option->nv_str); - p += sprintf(p, "\n"); + totlen = snprintf(new_contents, sizeof new_contents, + "#define\t%s\t%s\n", + option->nv_name, option->nv_str); + else + totlen = snprintf(new_contents, sizeof new_contents, + "#define\t%s\n", + option->nv_name); + } + + if (totlen >= sizeof new_contents) { + fprintf(stderr, "config: string too long\n"); + return (1); } /* diff --git a/usr.sbin/config/ukcutil.c b/usr.sbin/config/ukcutil.c index 97c3bb1f336..f322c0c6501 100644 --- a/usr.sbin/config/ukcutil.c +++ b/usr.sbin/config/ukcutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ukcutil.c,v 1.10 2002/05/02 12:59:54 miod Exp $ */ +/* $OpenBSD: ukcutil.c,v 1.11 2002/07/14 02:59:41 deraadt Exp $ */ /* * Copyright (c) 1999-2001 Mats O Jansson. All rights reserved. @@ -30,7 +30,7 @@ */ #ifndef LINT -static char rcsid[] = "$OpenBSD: ukcutil.c,v 1.10 2002/05/02 12:59:54 miod Exp $"; +static char rcsid[] = "$OpenBSD: ukcutil.c,v 1.11 2002/07/14 02:59:41 deraadt Exp $"; #endif #include <sys/types.h> @@ -1355,7 +1355,7 @@ again: printf("Invalid command '%s'. Try 'help'.\n", cmd.cmd); continue; } else - strcpy(cmd.cmd, cmd_table[i].cmd); + strlcpy(cmd.cmd, cmd_table[i].cmd, sizeof cmd.cmd); /* Call function */ st = cmd_table[i].fcn(&cmd); diff --git a/usr.sbin/config/util.c b/usr.sbin/config/util.c index 3489c3c8eae..19a82641a73 100644 --- a/usr.sbin/config/util.c +++ b/usr.sbin/config/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.9 2002/03/14 16:44:24 mpech Exp $ */ +/* $OpenBSD: util.c,v 1.10 2002/07/14 02:59:41 deraadt Exp $ */ /* $NetBSD: util.c,v 1.5 1996/08/31 20:58:29 mycroft Exp $ */ /* @@ -101,9 +101,10 @@ sourcepath(file) const char *file; { char *cp; + int len = strlen(srcdir) + 1 + strlen(file) + 1; - cp = emalloc(strlen(srcdir) + 1 + strlen(file) + 1); - (void)sprintf(cp, "%s/%s", srcdir, file); + cp = emalloc(len); + (void)snprintf(cp, len, "%s/%s", srcdir, file); return (cp); } |