diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-01-02 20:01:36 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-01-02 20:01:36 +0000 |
commit | 28aa656edf9b84e10b2d2edd658ea607f3d5b075 (patch) | |
tree | 0ac70efec0ee9be2bc0492047960a92e63bb52ac /usr.sbin/amd/fsinfo | |
parent | 3103e349fd412c945e349140bb30fba29711d52d (diff) |
fix sprintf overflow, found by spock@techfour.net, just a better fix of mine.
user __progname, err/warn.
Diffstat (limited to 'usr.sbin/amd/fsinfo')
-rw-r--r-- | usr.sbin/amd/fsinfo/fsi_lex.l | 4 | ||||
-rw-r--r-- | usr.sbin/amd/fsinfo/fsi_util.c | 10 | ||||
-rw-r--r-- | usr.sbin/amd/fsinfo/fsinfo.c | 41 | ||||
-rw-r--r-- | usr.sbin/amd/fsinfo/fsinfo.h | 5 |
4 files changed, 26 insertions, 34 deletions
diff --git a/usr.sbin/amd/fsinfo/fsi_lex.l b/usr.sbin/amd/fsinfo/fsi_lex.l index 5e9d87e7ec6..24e436cd5dd 100644 --- a/usr.sbin/amd/fsinfo/fsi_lex.l +++ b/usr.sbin/amd/fsinfo/fsi_lex.l @@ -37,7 +37,7 @@ * SUCH DAMAGE. * * from: @(#)fsi_lex.l 8.2 (Berkeley) 2/17/94 - * $Id: fsi_lex.l,v 1.1 1995/10/18 08:47:18 deraadt Exp $ + * $Id: fsi_lex.l,v 1.2 2001/01/02 20:01:34 mickey Exp $ */ /* @@ -262,7 +262,7 @@ static int first = 1; first = 0; return 0; } else { - perror(prog); + warn(prog); } } diff --git a/usr.sbin/amd/fsinfo/fsi_util.c b/usr.sbin/amd/fsinfo/fsi_util.c index adc1562237a..32258a97326 100644 --- a/usr.sbin/amd/fsinfo/fsi_util.c +++ b/usr.sbin/amd/fsinfo/fsi_util.c @@ -33,7 +33,7 @@ * SUCH DAMAGE. * * from: @(#)fsi_util.c 8.1 (Berkeley) 6/6/93 - * $Id: fsi_util.c,v 1.4 1997/02/17 22:13:28 deraadt Exp $ + * $Id: fsi_util.c,v 1.5 2001/01/02 20:01:35 mickey Exp $ */ #include "../fsinfo/fsinfo.h" @@ -45,7 +45,7 @@ void error(s, s1, s2, s3, s4) char *s, *s1, *s2, *s3, *s4; { col_cleanup(0); - fprintf(stderr, "%s: Error, ", progname); + fprintf(stderr, "%s: Error, ", __progname); fprintf(stderr, s, s1, s2, s3, s4); fputc('\n', stderr); errors++; @@ -77,7 +77,7 @@ void fatal(s, s1, s2, s3, s4) char *s, *s1, *s2, *s3, *s4; { col_cleanup(1); - fprintf(stderr, "%s: Fatal, ", progname); + fprintf(stderr, "%s: Fatal, ", __progname); fprintf(stderr, s, s1, s2, s3, s4); fputc('\n', stderr); exit(1); @@ -108,7 +108,7 @@ char *s, *s1, *s2, *s3, *s4; { if (verbose > 0) { fputc('#', stdout); - fprintf(stdout, "%s: ", progname); + fprintf(stdout, "%s: ", __progname); fprintf(stdout, s, s1, s2, s3, s4); putc('\n', stdout); } @@ -140,7 +140,7 @@ FILE *fp; # \"%s\" run by %s@%s on %s\ #\n\ ", - progname, username, hostname, cp); + __progname, username, hostname, cp); } static int show_range = 10; diff --git a/usr.sbin/amd/fsinfo/fsinfo.c b/usr.sbin/amd/fsinfo/fsinfo.c index 6ffaa3b5a4f..5466843846d 100644 --- a/usr.sbin/amd/fsinfo/fsinfo.c +++ b/usr.sbin/amd/fsinfo/fsinfo.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * from: @(#)fsinfo.c 8.1 (Berkeley) 6/6/93 - * $Id: fsinfo.c,v 1.3 1997/01/15 23:43:47 millert Exp $ + * $Id: fsinfo.c,v 1.4 2001/01/02 20:01:35 mickey Exp $ */ #ifndef lint @@ -67,7 +67,6 @@ int verbose; char idvbuf[1024]; char **g_argv; -char *progname; /* * Output file prefixes @@ -90,19 +89,7 @@ char *v[]; int ch; int usage = 0; char *iptr = idvbuf; - - /* - * Determine program name - */ - if (v[0]) { - progname = strrchr(v[0], '/'); - if (progname && progname[1]) - progname++; - else - progname = v[0]; - } - if (!progname) - progname = "fsinfo"; + int iptr_size = sizeof(idvbuf); while ((ch = getopt(c, v, "a:b:d:e:f:h:m:D:U:I:qv")) != -1) switch (ch) { @@ -144,8 +131,13 @@ char *v[]; verbose = 1; break; case 'I': case 'D': case 'U': - sprintf(iptr, "-%c%s ", ch, optarg); - iptr += strlen(iptr); + if (snprintf(iptr, iptr_size, "-%c%s ", ch, optarg) >= iptr_size) + usage++; + else { + size_t l = strlen(iptr); + iptr_size -= l; + iptr += strlen(iptr); + } break; default: usage++; @@ -165,7 +157,7 @@ char *v[]; "\ Usage: %s [-v] [-a autodir] [-h hostname] [-b bootparams] [-d dumpsets]\n\ \t[-e exports] [-f fstabs] [-m automounts]\n\ -\t[-I dir] [-D|-U string[=string]] config ...\n", progname); +\t[-I dir] [-D|-U string[=string]] config ...\n", __progname); exit(1); } @@ -202,9 +194,10 @@ static char *find_username() /* * MAIN */ +int main(argc, argv) -int argc; -char *argv[]; + int argc; + char *argv[]; { /* * Process arguments @@ -214,10 +207,8 @@ char *argv[]; /* * If no hostname given then use the local name */ - if (!*hostname && gethostname(hostname, sizeof(hostname)) < 0) { - perror("gethostname"); - exit(1); - } + if (!*hostname && gethostname(hostname, sizeof(hostname)) < 0) + err(1, "gethostname"); /* * Get the username @@ -269,5 +260,5 @@ char *argv[]; col_cleanup(1); - exit(errors); + return (errors); } diff --git a/usr.sbin/amd/fsinfo/fsinfo.h b/usr.sbin/amd/fsinfo/fsinfo.h index 077d9f8145d..3cdd1758246 100644 --- a/usr.sbin/amd/fsinfo/fsinfo.h +++ b/usr.sbin/amd/fsinfo/fsinfo.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * from: @(#)fsinfo.h 8.1 (Berkeley) 6/6/93 - * $Id: fsinfo.h,v 1.2 1997/01/31 14:42:11 graichen Exp $ + * $Id: fsinfo.h,v 1.3 2001/01/02 20:01:35 mickey Exp $ */ /* @@ -84,6 +84,7 @@ typedef char *voidp; #include <string.h> #include <stdlib.h> +#include <err.h> #include "fsi_data.h" @@ -123,7 +124,7 @@ extern char *fsmount_strings[]; extern char *host_strings[]; extern char *ether_if_strings[]; extern char *autodir; -extern char *progname; +extern char *__progname; extern char hostname[]; extern char *username; extern char **g_argv; |