diff options
| author | mjl <mjl@NetBSD.org> | 2000-01-14 06:53:48 +0000 |
|---|---|---|
| committer | mjl <mjl@NetBSD.org> | 2000-01-14 06:53:48 +0000 |
| commit | ec1d133cd389f9abb6bc77b72f7d23dc038d3697 (patch) | |
| tree | 04e44b9809a5a5a2e3ab6132d5c7fb0b3fe80fda /usr.bin/error | |
| parent | 9dff294326c5bee52ac0fded888d0d76fcda6ebb (diff) | |
Eliminate hard coded buffer sizes in fgets() statements, use
strlcpy() to avoid buffer overflows, increase filename buffer
to MAXPATHLEN. (from OpenBSD)
Diffstat (limited to 'usr.bin/error')
| -rw-r--r-- | usr.bin/error/filter.c | 22 | ||||
| -rw-r--r-- | usr.bin/error/pi.c | 6 | ||||
| -rw-r--r-- | usr.bin/error/subr.c | 6 |
3 files changed, 18 insertions, 16 deletions
diff --git a/usr.bin/error/filter.c b/usr.bin/error/filter.c index 2b50a55b5e7..58c621af9f8 100644 --- a/usr.bin/error/filter.c +++ b/usr.bin/error/filter.c @@ -1,4 +1,4 @@ -/* $NetBSD: filter.c,v 1.5 1998/11/06 23:10:08 christos Exp $ */ +/* $NetBSD: filter.c,v 1.6 2000/01/14 06:53:48 mjl Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,10 +38,10 @@ #if 0 static char sccsid[] = "@(#)filter.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: filter.c,v 1.5 1998/11/06 23:10:08 christos Exp $"); +__RCSID("$NetBSD: filter.c,v 1.6 2000/01/14 06:53:48 mjl Exp $"); #endif /* not lint */ -#include <sys/types.h> +#include <sys/param.h> #include <pwd.h> #include <unistd.h> #include <stdio.h> @@ -73,8 +73,8 @@ getignored(auxname) int i; FILE *fyle; char inbuffer[256]; - int uid; - char filename[128]; + uid_t uid; + char filename[MAXPATHLEN]; char *username; struct passwd *passwdentry; @@ -90,10 +90,10 @@ getignored(auxname) if ( (passwdentry = (struct passwd *)getpwnam(username)) == NULL) return; } - strcpy(filename, passwdentry->pw_dir); - (void)strcat(filename, ERRORNAME); + strlcpy(filename, passwdentry->pw_dir, sizeof(filename)); + (void)strlcat(filename, ERRORNAME, sizeof(filename)); } else - (void)strcpy(filename, auxname); + (void)strlcpy(filename, auxname, sizeof(filename)); #ifdef FULLDEBUG printf("Opening file \"%s\" to read names to ignore.\n", filename); @@ -108,7 +108,8 @@ getignored(auxname) /* * Make the first pass through the file, counting lines */ - for (nignored = 0; fgets(inbuffer, 255, fyle) != NULL; nignored++) + for (nignored = 0; + fgets(inbuffer, sizeof(inbuffer)-1, fyle) != NULL; nignored++) continue; names_ignored = (char **)Calloc(nignored+1, sizeof (char *)); fclose(fyle); @@ -120,7 +121,8 @@ getignored(auxname) nignored = 0; return; } - for (i=0; i < nignored && (fgets (inbuffer, 255, fyle) != NULL); i++){ + for (i=0; i < nignored && + (fgets (inbuffer, sizeof(inbuffer)-1, fyle) != NULL); i++){ names_ignored[i] = strsave(inbuffer); (void)substitute(names_ignored[i], '\n', '\0'); } diff --git a/usr.bin/error/pi.c b/usr.bin/error/pi.c index 8ecd6bce4f9..aa5b6dd9e45 100644 --- a/usr.bin/error/pi.c +++ b/usr.bin/error/pi.c @@ -1,4 +1,4 @@ -/* $NetBSD: pi.c,v 1.6 1998/11/06 23:10:08 christos Exp $ */ +/* $NetBSD: pi.c,v 1.7 2000/01/14 06:53:48 mjl Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)pi.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: pi.c,v 1.6 1998/11/06 23:10:08 christos Exp $"); +__RCSID("$NetBSD: pi.c,v 1.7 2000/01/14 06:53:48 mjl Exp $"); #endif /* not lint */ #include <stdio.h> @@ -248,7 +248,7 @@ pi() * Where the | is intended to be a down arrow, so that * the pi error messages can be inserted above the * line in error, instead of below. (All of the other - * languages put thier messages before the source line, + * languages put their messages before the source line, * instead of after it as does pi.) * * where the pointer to the error has been truncated diff --git a/usr.bin/error/subr.c b/usr.bin/error/subr.c index 0ce1ff48dcb..029e02fb5e0 100644 --- a/usr.bin/error/subr.c +++ b/usr.bin/error/subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr.c,v 1.8 1999/05/15 19:05:13 christos Exp $ */ +/* $NetBSD: subr.c,v 1.9 2000/01/14 06:53:48 mjl Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: subr.c,v 1.8 1999/05/15 19:05:13 christos Exp $"); +__RCSID("$NetBSD: subr.c,v 1.9 2000/01/14 06:53:48 mjl Exp $"); #endif /* not lint */ #include <ctype.h> @@ -82,7 +82,7 @@ Calloc(nelements, size) int size; { char *back; - if ( (back = (char *)calloc(nelements, size)) == (char *)NULL) + if ( (back = (char *)calloc(nelements, size)) == NULL) errx(1, "Ran out of memory."); return(back); } |
