Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Jul 2003 06:10:26 -0700 (PDT)
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/54672: [PATCH] fix gcc 3.3 compiler warning for ifconfig(8)
Message-ID:  <200307211310.h6LDAQOr020395@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/54672; it has been noted by GNATS.

From: Bruce Evans <bde@zeta.org.au>
To: Lukas Ertl <l.ertl@univie.ac.at>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/54672: [PATCH] fix gcc 3.3 compiler warning for ifconfig(8)
Date: Mon, 21 Jul 2003 23:03:50 +1000 (EST)

 On Mon, 21 Jul 2003, Lukas Ertl wrote:
 
 > On Mon, 21 Jul 2003, Bruce Evans wrote:
 > > Using strtoul() as mentioned in the XXX before the above code would avoid
 > > the warning less accidentally since 0xffff < ULONG_MAX on all machines.
 >
 > Well, would this patch be better:
 
 I'm afraid not, since it has much the same parsing and overflow handing
 bugs as the old version despite being much larger, and it has some new
 style bugs.
 
 > Index: sbin/ifconfig/ifconfig.c
 > ===================================================================
 > RCS file: /usr/local/bsdcvs/src/sbin/ifconfig/ifconfig.c,v
 > retrieving revision 1.90
 > diff -u -u -r1.90 ifconfig.c
 > --- sbin/ifconfig/ifconfig.c	28 Apr 2003 16:37:38 -0000	1.90
 > +++ sbin/ifconfig/ifconfig.c	21 Jul 2003 11:50:33 -0000
 > @@ -1680,17 +1680,34 @@
 > ...
 > -	u_short	first = 123, last = 123;
 > +	u_int	first = 123, last = 123;
 > +	char	*p, *endptr;
 
 The new lines should be:
 
 	char *endptr, *p;
 	u_long first, last;
 
 This fixes about 4 style bugs (initialization, indentation, inter-line order
 and intra-line order) , and 1 overflow bug (see below).
 
 > +
 > +	if ((p = strchr(range, '-')) == NULL)
 > +		errx(1, "illegal range '%s'", range);
 
 strtoul() could be used to read up to the '-' more directly.
 
 There are complications for invalid formats with '-' signs in the
 numbers.  Both strtoul() and sscanf() will parse the '-' signs as
 parts of numbers, but we don't want that here.  I think we also
 don't want any leading whitespace.
 
 > +	first = strtoul(range, &endptr, 10);
 
 `first' needs to have type u_long so that overflow can't occur before
 the range check.  OTOH, we don't need to handle ERANGE errors since
 ULONG_MAX will fail the range check.
 
 Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200307211310.h6LDAQOr020395>