summaryrefslogtreecommitdiffstats
path: root/usr.sbin/config/mkoptions.c
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2000-11-21 19:58:55 +0000
committerimp <imp@FreeBSD.org>2000-11-21 19:58:55 +0000
commitae30fcfec826cbc1aef366e520ae248267e5ac2e (patch)
treeaf280d537eb05b68e0199c48ee9a14999b89beb8 /usr.sbin/config/mkoptions.c
parent92be31d0b583b42dee21f006ea62f231ad132326 (diff)
downloadFreeBSD-src-ae30fcfec826cbc1aef366e520ae248267e5ac2e.zip
FreeBSD-src-ae30fcfec826cbc1aef366e520ae248267e5ac2e.tar.gz
Fix buffer overflows in filenames. If you had a path > 80 characters
for your /usr/obj/path/to/my/files path to the kernel, then weird things happened. make buildkernel would fail because config was dumping core or generating bad file names (depending on the lenght of the path). While I was here, also use strlcpy, strlcat and snprintf (or asprintf) as necessary. Minor format policing for the snprintf calls as well.
Diffstat (limited to 'usr.sbin/config/mkoptions.c')
-rw-r--r--usr.sbin/config/mkoptions.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c
index da0fba4..9496ca4 100644
--- a/usr.sbin/config/mkoptions.c
+++ b/usr.sbin/config/mkoptions.c
@@ -48,6 +48,7 @@ static const char rcsid[] =
#include <err.h>
#include <stdio.h>
#include <string.h>
+#include <sys/param.h>
#include "config.h"
#include "y.tab.h"
@@ -274,21 +275,21 @@ do_option(char *name)
static char *
tooption(char *name)
{
- static char hbuf[80];
- char nbuf[80];
+ static char hbuf[MAXPATHLEN];
+ char nbuf[MAXPATHLEN];
struct opt_list *po;
/* "cannot happen"? the otab list should be complete.. */
- (void) strcpy(nbuf, "options.h");
+ (void) strlcpy(nbuf, "options.h", sizeof(nbuf));
for (po = otab ; po != 0; po = po->o_next) {
if (eq(po->o_name, name)) {
- strcpy(nbuf, po->o_file);
+ strlcpy(nbuf, po->o_file, sizeof(nbuf));
break;
}
}
- (void) strcpy(hbuf, path(nbuf));
+ (void) strlcpy(hbuf, path(nbuf), sizeof(hbuf));
return (hbuf);
}
@@ -299,18 +300,18 @@ static void
read_options(void)
{
FILE *fp;
- char fname[80];
+ char fname[MAXPATHLEN];
char *wd, *this, *val;
struct opt_list *po;
int first = 1;
- char genopt[80];
+ char genopt[MAXPATHLEN];
otab = 0;
if (ident == NULL) {
printf("no ident line specified\n");
exit(1);
}
- (void) snprintf(fname, sizeof fname, "../../conf/options");
+ (void) snprintf(fname, sizeof(fname), "../../conf/options");
openit:
fp = fopen(fname, "r");
if (fp == 0) {
@@ -352,7 +353,7 @@ next:
return;
if (val == 0) {
char *s = ns(this);
- (void) snprintf(genopt, sizeof genopt, "opt_%s.h", lower(s));
+ (void) snprintf(genopt, sizeof(genopt), "opt_%s.h", lower(s));
val = genopt;
free(s);
}
OpenPOWER on IntegriCloud