From owner-cvs-src@FreeBSD.ORG Wed Jan 5 15:09:20 2005 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B136016A4CE; Wed, 5 Jan 2005 15:09:20 +0000 (GMT) Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id B2AF943D54; Wed, 5 Jan 2005 15:09:19 +0000 (GMT) (envelope-from keramida@freebsd.org) Received: from orion.daedalusnetworks.priv (aris.bedc.ondsl.gr [62.103.39.226])j05F9Hbr006732; Wed, 5 Jan 2005 17:09:18 +0200 Received: from orion.daedalusnetworks.priv (orion [127.0.0.1]) j05F9HPS001874; Wed, 5 Jan 2005 17:09:17 +0200 (EET) (envelope-from keramida@freebsd.org) Received: (from keramida@localhost)j05F9Hbl001873; Wed, 5 Jan 2005 17:09:17 +0200 (EET) (envelope-from keramida@freebsd.org) Date: Wed, 5 Jan 2005 17:09:17 +0200 From: Giorgos Keramidas To: Scott Long Message-ID: <20050105150917.GA1592@orion.daedalusnetworks.priv> References: <200501031903.j03J3eBd044669@repoman.freebsd.org> <41D9A839.6000800@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41D9A839.6000800@freebsd.org> cc: cvs-src@freebsd.org cc: src-committers@freebsd.org cc: Robert Watson cc: cvs-all@freebsd.org Subject: Re: cvs commit: src/sbin/badsect badsect.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Jan 2005 15:09:21 -0000 On 2005-01-03 13:16, Scott Long wrote: >Robert Watson wrote: >>rwatson 2005-01-03 19:03:40 UTC >> >> FreeBSD src repository >> >> Modified files: >> sbin/badsect badsect.c >> Log: >> The badsect(8) utility uses atol(), which doesn't allow very good error >> checking and only recognizes numbers in base 10. The attached patch >> checks errno after strtol() and uses a base of 0 to allow octal, or hex >> sector numbers too. >> >> PR: 73112 >> Submitted by: keramida >> MFC after: 2 weeks >> >> Revision Changes Path >> 1.21 +4 -1 src/sbin/badsect/badsect.c > > I'd argue that atol() is buggy for a number of other reasons also, > mainly that it means that you're limited to 2^31 sectors. Maybe this > should change to strtoull() ? Ideally, if that's not a problem, we should go for uintmax_t, since `number' in this case is then stored in a daddr_t, which is 64-bits wide. How about something like this? I could find no easy way to check for overflow of daddr_t, so this is still not quite perfect but it's an improvement that may help with Really-Huge(TM) disks. %%% Index: badsect.c =================================================================== RCS file: /home/ncvs/src/sbin/badsect/badsect.c,v retrieving revision 1.21 diff -u -u -r1.21 badsect.c --- badsect.c 3 Jan 2005 19:03:40 -0000 1.21 +++ badsect.c 5 Jan 2005 15:03:39 -0000 @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #include @@ -94,6 +95,7 @@ DIR *dirp; char name[2 * MAXPATHLEN]; char *name_dir_end; + char *errp; if (argc < 3) usage(); @@ -124,8 +126,11 @@ err(7, "%s", name); } for (argc -= 2, argv += 2; argc > 0; argc--, argv++) { - number = strtol(*argv, NULL, 0); - if (errno == EINVAL || errno == ERANGE) + errp = NULL; + errno = 0; + number = strtoumax(*argv, &errp, 0); + if (errno != 0 || errp != NULL || (errp != NULL && + *errp != '\0' && *argv != NULL && **argv != '\0')) err(8, "%s", *argv); if (chkuse(number, 1)) continue; %%%