mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-01 08:27:59 +00:00
* Check getopt()'s return with -1, not EOF
* protect a few potential buffer overflows Obtained from: NetBSD
This commit is contained in:
parent
aad735d675
commit
274bbe3187
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=38500
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user