From owner-freebsd-bugs@FreeBSD.ORG Mon Jul 21 06:10:27 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 72C7C37B401 for ; Mon, 21 Jul 2003 06:10:27 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6C64A43FBF for ; Mon, 21 Jul 2003 06:10:26 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h6LDAQUp020402 for ; Mon, 21 Jul 2003 06:10:26 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h6LDAQOr020395; Mon, 21 Jul 2003 06:10:26 -0700 (PDT) Date: Mon, 21 Jul 2003 06:10:26 -0700 (PDT) Message-Id: <200307211310.h6LDAQOr020395@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Evans Subject: Re: bin/54672: [PATCH] fix gcc 3.3 compiler warning for ifconfig(8) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Bruce Evans List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jul 2003 13:10:27 -0000 The following reply was made to PR bin/54672; it has been noted by GNATS. From: Bruce Evans To: Lukas Ertl 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