From owner-freebsd-bugs@FreeBSD.ORG Fri Oct 29 21:30:31 2004 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 6F81A16A4CF for ; Fri, 29 Oct 2004 21:30:31 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5370B43D5E for ; Fri, 29 Oct 2004 21:30:31 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i9TLUUJ5005685 for ; Fri, 29 Oct 2004 21:30:30 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i9TLUUY8005684; Fri, 29 Oct 2004 21:30:30 GMT (envelope-from gnats) Date: Fri, 29 Oct 2004 21:30:30 GMT Message-Id: <200410292130.i9TLUUY8005684@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Dima Dorfman Subject: Re: bin/73112: change atol() to strtol() in badsect X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Dima Dorfman List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Oct 2004 21:30:31 -0000 The following reply was made to PR bin/73112; it has been noted by GNATS. From: Dima Dorfman To: Giorgos Keramidas Cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: bin/73112: change atol() to strtol() in badsect Date: Fri, 29 Oct 2004 21:20:52 +0000 Giorgos Keramidas wrote: > > >Number: 73112 > >Synopsis: change atol() to strtol() in badsect > > Index: badsect.c > =================================================================== > RCS file: /home/ncvs/src/sbin/badsect/badsect.c,v > retrieving revision 1.20 > diff -u -u -r1.20 badsect.c > --- badsect.c 9 Apr 2004 19:58:25 -0000 1.20 > +++ badsect.c 25 Oct 2004 12:00:37 -0000 > @@ -123,7 +124,9 @@ > err(7, "%s", name); > } > for (argc -= 2, argv += 2; argc > 0; argc--, argv++) { > - number = atol(*argv); > + number = strtol(*argv, NULL, 0); > + if (errno == EINVAL || errno == ERANGE) > + err(8, "%s", *argv); The error handling here is incorrect. strtol never clears errno, and it doesn't consider it an error if part of the string wasn't converted. Something like this is necessary: char *ep; ... errno = 0; number = strtol(*argv, &ep, 0); if (*ep != '\0' || errno != 0) ...