From owner-freebsd-bugs@FreeBSD.ORG Tue Jul 22 03:30:16 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 7FD8F37B401 for ; Tue, 22 Jul 2003 03:30:16 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1ED8A43F93 for ; Tue, 22 Jul 2003 03:30:16 -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 h6MAUFUp098288 for ; Tue, 22 Jul 2003 03:30:15 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h6MAUFns098287; Tue, 22 Jul 2003 03:30:15 -0700 (PDT) Date: Tue, 22 Jul 2003 03:30:15 -0700 (PDT) Message-Id: <200307221030.h6MAUFns098287@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: Tue, 22 Jul 2003 10:30:16 -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: Tue, 22 Jul 2003 20:22:36 +1000 (EST) On Mon, 21 Jul 2003, Lukas Ertl wrote: > On Mon, 21 Jul 2003, Bruce Evans wrote: > > > On Mon, 21 Jul 2003, Lukas Ertl wrote: > > > ... > > > + > > > + 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. > > So we need strchr(), don't we? No. strchr() will find the first '-' in the invalid input "-123-456", and I think recovering from this mess would be harder than not getting into it. Another example of invalid input that tends to get accepted if any character except the digits is parsed in a non-per-char way: " \t-123- \t-456". Pseudocode for rejecting minus signs and whitespace: assert(isdigit((u_char)*range); first = strtoul(range, &endptr, 10); assert(*endptr == '-'); endptr++; assert(isdigit((u_char)*endptr); last = strtoul(endptr, &endptr, 10); assert(*endptr == '\0'); Hmm. It wouldn't hurt to accept whitespace, and strtoul will handle minus signs in a way that will cause an error later ("-" -> 0 or -ULONG_MAX), so we can let strtoul() parse almost everything after all: first = strtoul(range, &endptr, 10); assert(endptr != range && *endptr == '-'); lastptr = endptr + 1; last = strtoul(lastptr, &endptr, 10); assert(endptr != lastptr && *endptr == '\0'); Bruce