diff options
author | David E. O'Brien <obrien@FreeBSD.org> | 1998-08-23 22:52:09 +0000 |
---|---|---|
committer | David E. O'Brien <obrien@FreeBSD.org> | 1998-08-23 22:52:09 +0000 |
commit | 274bbe3187aa89b166eae8ab17f48d25438cb818 (patch) | |
tree | 4562786f7101b8fb46e77bbec0867074fcadef18 | |
parent | aad735d675a6e8bb77d3806b6aa34ef384a02b0e (diff) | |
download | src-274bbe3187aa89b166eae8ab17f48d25438cb818.tar.gz src-274bbe3187aa89b166eae8ab17f48d25438cb818.zip |
* Check getopt()'s return with -1, not EOF
* protect a few potential buffer overflows
Obtained from: NetBSD
Notes
Notes:
svn path=/head/; revision=38500
-rw-r--r-- | contrib/amd/amd/amd.c | 7 | ||||
-rw-r--r-- | contrib/amd/amq/amq.c | 6 | ||||
-rw-r--r-- | contrib/amd/fixmount/fixmount.c | 7 | ||||
-rw-r--r-- | contrib/amd/fsinfo/fsinfo.c | 4 | ||||
-rw-r--r-- | contrib/amd/hlfsd/hlfsd.c | 7 | ||||
-rw-r--r-- | contrib/amd/hlfsd/homedir.c | 6 | ||||
-rw-r--r-- | contrib/amd/mk-amd-map/mk-amd-map.c | 5 | ||||
-rw-r--r-- | contrib/amd/wire-test/wire-test.c | 7 |
8 files changed, 27 insertions, 22 deletions
diff --git a/contrib/amd/amd/amd.c b/contrib/amd/amd/amd.c index 7ef2ce7ed69d..3740529f0c99 100644 --- a/contrib/amd/amd/amd.c +++ b/contrib/amd/amd/amd.c @@ -38,7 +38,7 @@ * * %W% (Berkeley) %G% * - * $Id: amd.c,v 5.2.2.1 1992/02/09 15:08:15 jsp beta $ + * $Id: amd.c,v 1.1.1.1 1998/08/23 22:07:20 obrien Exp $ * */ @@ -57,8 +57,8 @@ struct amu_global_options gopt; /* where global options are stored */ char pid_fsname[16 + MAXHOSTNAMELEN]; /* "kiska.southseas.nz:(pid%d)" */ char *progname; /* "amd" */ char *hostdomain = "unknown.domain"; -char hostname[MAXHOSTNAMELEN] = "localhost"; /* Hostname */ -char hostd[2 * MAXHOSTNAMELEN]; /* Host+domain */ +char hostname[MAXHOSTNAMELEN + 1] = "localhost"; /* Hostname */ +char hostd[2 * MAXHOSTNAMELEN + 1]; /* Host+domain */ char *endian = ARCH_ENDIAN; /* Big or Little endian */ char *cpu = HOST_CPU; /* CPU type */ char *PrimNetName; /* name of primary network */ @@ -349,6 +349,7 @@ main(int argc, char *argv[]) plog(XLOG_FATAL, "gethostname: %m"); going_down(1); } + hostname[sizeof(hostname) - 1] = '\0'; /* * Check it makes sense diff --git a/contrib/amd/amq/amq.c b/contrib/amd/amq/amq.c index 7fba9b1c0d1d..bd81d4f3516c 100644 --- a/contrib/amd/amq/amq.c +++ b/contrib/amd/amq/amq.c @@ -38,7 +38,7 @@ * * %W% (Berkeley) %G% * - * $Id: amq.c,v 5.2.2.1 1992/02/09 15:09:16 jsp beta $ + * $Id: amq.c,v 1.1.1.1 1998/08/23 22:07:20 obrien Exp $ * */ @@ -54,7 +54,7 @@ char copyright[] = "\ @(#)Copyright (c) 1990 The Regents of the University of California.\n\ @(#)All rights reserved.\n"; #if __GNUC__ < 2 -static char rcsid[] = "$Id: amq.c,v 6.0 1997-1998/01/01 15:09:16 ezk $"; +static char rcsid[] = "$Id: amq.c,v 1.1.1.1 1998/08/23 22:07:20 obrien Exp $"; static char sccsid[] = "%W% (Berkeley) %G%"; #endif /* __GNUC__ < 2 */ #endif /* not lint */ @@ -330,7 +330,7 @@ main(int argc, char *argv[]) /* * Parse arguments */ - while ((opt_ch = getopt(argc, argv, "fh:l:msuvx:D:M:pP:TU")) != EOF) + while ((opt_ch = getopt(argc, argv, "fh:l:msuvx:D:M:pP:TU")) != -1) switch (opt_ch) { case 'f': flush_flag = 1; diff --git a/contrib/amd/fixmount/fixmount.c b/contrib/amd/fixmount/fixmount.c index 9769a419afd2..53c7807038e7 100644 --- a/contrib/amd/fixmount/fixmount.c +++ b/contrib/amd/fixmount/fixmount.c @@ -38,7 +38,7 @@ * * %W% (Berkeley) %G% * - * $Id: fixmount.c,v 5.2.2.2 1992/05/31 16:35:45 jsp Exp $ + * $Id: fixmount.c,v 1.1.1.1 1998/08/23 22:07:20 obrien Exp $ * */ @@ -68,7 +68,7 @@ extern int fixmount_check_mount(char *host, struct in_addr hostaddr, char *path) static char dir_path[NFS_MAXPATHLEN]; static char localhost[] = "localhost"; -static char thishost[MAXHOSTNAMELEN] = ""; +static char thishost[MAXHOSTNAMELEN + 1] = ""; static exports mntexports; static int quiet = 0; static int type = 0; @@ -288,7 +288,7 @@ main(int argc, char *argv[]) register int rpcs = 0; struct timeval tv; - while ((ch = getopt(argc, argv, "adervAqfh:")) != EOF) + while ((ch = getopt(argc, argv, "adervAqfh:")) != -1) switch ((char) ch) { case 'a': @@ -354,6 +354,7 @@ main(int argc, char *argv[]) perror("gethostname"); exit(1); } + thishost[sizeof(thishost) - 1] = '\0'; /* * We need the hostname as it appears to the other side's diff --git a/contrib/amd/fsinfo/fsinfo.c b/contrib/amd/fsinfo/fsinfo.c index e2632bff4a22..abb1c50f3c76 100644 --- a/contrib/amd/fsinfo/fsinfo.c +++ b/contrib/amd/fsinfo/fsinfo.c @@ -38,7 +38,7 @@ * * %W% (Berkeley) %G% * - * $Id: fsinfo.c,v 5.2.2.1 1992/02/09 15:09:33 jsp beta $ + * $Id: fsinfo.c,v 1.1.1.1 1998/08/23 22:07:20 obrien Exp $ * */ @@ -109,7 +109,7 @@ fsi_get_args(int c, char *v[]) if (!progname) progname = "fsinfo"; - while ((ch = getopt(c, v, "a:b:d:e:f:h:m:D:U:I:qv")) != EOF) + while ((ch = getopt(c, v, "a:b:d:e:f:h:m:D:U:I:qv")) != -1) switch (ch) { diff --git a/contrib/amd/hlfsd/hlfsd.c b/contrib/amd/hlfsd/hlfsd.c index 388c65b2189d..1934824cbfe2 100644 --- a/contrib/amd/hlfsd/hlfsd.c +++ b/contrib/amd/hlfsd/hlfsd.c @@ -38,7 +38,7 @@ * * %W% (Berkeley) %G% * - * $Id: hlfsd.c,v 1.11 1994/11/06 00:19:52 ezk Exp ezk $ + * $Id: hlfsd.c,v 1.1.1.1 1998/08/23 22:07:20 obrien Exp $ * * HLFSD was written at Columbia University Computer Science Department, by * Erez Zadok <ezk@cs.columbia.edu> and Alexander Dupuy <dupuy@cs.columbia.edu> @@ -85,7 +85,7 @@ char *logfile = DEFAULT_LOGFILE; char *passwdfile = NULL; /* alternate passwd file to use */ char *progname; char *slinkname = 0; -char hostname[MAXHOSTNAMELEN] = "localhost"; +char hostname[MAXHOSTNAMELEN + 1] = "localhost"; int cache_interval = DEFAULT_CACHE_INTERVAL; int foreground = 1; /* This is the top-level server */ gid_t hlfs_gid = (gid_t) INVALIDID; @@ -308,7 +308,8 @@ main(int argc, char *argv[]) } /* get hostname for logging and open log before we reset umask */ - gethostname(hostname, MAXHOSTNAMELEN); + gethostname(hostname, sizeof hostname); + hostname[sizeof(hostname) - 1] = '\0'; if ((dot = strchr(hostname, '.')) != NULL) *dot = '\0'; if (logfile) diff --git a/contrib/amd/hlfsd/homedir.c b/contrib/amd/hlfsd/homedir.c index d6df58e02b2d..b8c45c2ff534 100644 --- a/contrib/amd/hlfsd/homedir.c +++ b/contrib/amd/hlfsd/homedir.c @@ -38,7 +38,7 @@ * * %W% (Berkeley) %G% * - * $Id: homedir.c,v 1.16 1993/09/13 15:11:00 ezk Exp $ + * $Id: homedir.c,v 1.1.1.1 1998/08/23 22:07:20 obrien Exp $ * * HLFSD was written at Columbia University Computer Science Department, by * Erez Zadok <ezk@cs.columbia.edu> and Alexander Dupuy <dupuy@cs.columbia.edu> @@ -66,7 +66,7 @@ static struct passwd passwd_ent; static uid2home_t *lastchild; static uid2home_t *pwtab; static void delay(uid2home_t *, int); -static void table_add(int, char *, char *); +static void table_add(int, const char *, const char *); /* GLOBAL FUNCTIONS */ char *homeof(char *username); @@ -619,7 +619,7 @@ plt_reset(void) * n: user ID name */ static void -table_add(int u, char *h, char *n) +table_add(int u, const char *h, const char *n) { int i; diff --git a/contrib/amd/mk-amd-map/mk-amd-map.c b/contrib/amd/mk-amd-map/mk-amd-map.c index 2b4154008b44..3eba7b293b4b 100644 --- a/contrib/amd/mk-amd-map/mk-amd-map.c +++ b/contrib/amd/mk-amd-map/mk-amd-map.c @@ -38,7 +38,7 @@ * * %W% (Berkeley) %G% * - * $Id: mk-amd-map.c,v 5.2.2.1 1992/02/09 15:09:18 jsp beta $ + * $Id: mk-amd-map.c,v 1.1.1.1 1998/08/23 22:07:21 obrien Exp $ */ /* @@ -229,7 +229,7 @@ main(int argc, char *argv[]) extern int optind; /* test options */ - while ((ch = getopt(argc, argv, "p")) != EOF) + while ((ch = getopt(argc, argv, "p")) != -1) switch (ch) { case 'p': printit = 1; @@ -301,6 +301,7 @@ main(int argc, char *argv[]) int error = read_file(mapf, map, mapd); (void) close(mapfd); (void) fclose(mapf); + dbm_close(mapd); if (printit) { if (error) { fprintf(stderr, "Error creating ndbm map for %s\n", map); diff --git a/contrib/amd/wire-test/wire-test.c b/contrib/amd/wire-test/wire-test.c index c53094b35d7e..27525d03a1db 100644 --- a/contrib/amd/wire-test/wire-test.c +++ b/contrib/amd/wire-test/wire-test.c @@ -38,7 +38,7 @@ * * %W% (Berkeley) %G% * - * $Id: wire-test.c,v 5.2.2.2 1992/06/07 18:06:46 jsp Exp jsp $ + * $Id: wire-test.c,v 1.1.1.1 1998/08/23 22:07:21 obrien Exp $ * */ @@ -50,7 +50,7 @@ #define STRMAX 100 /* dummy variables */ -char *progname, hostname[MAXHOSTNAMELEN]; +char *progname, hostname[MAXHOSTNAMELEN + 1]; int orig_umask, foreground, debug_flags; pid_t mypid; serv_state amd_state; @@ -69,10 +69,11 @@ main(int argc, char **argv) mypid = getpid(); orig_umask = umask(0); - if (gethostname(hostname, MAXHOSTNAMELEN) < 0) { + if (gethostname(hostname, sizeof hostname) < 0) { perror(argv[0]); exit(1); } + hostname[sizeof(hostname) - 1] = '\0'; /* get list of networks */ getwire(&networkName1, &networkNumber1); |