bin/73112: change atol() to strtol() in badsect
Dima Dorfman
dd at freebsd.org
Fri Oct 29 14:30:31 PDT 2004
The following reply was made to PR bin/73112; it has been noted by GNATS.
From: Dima Dorfman <dd at freebsd.org>
To: Giorgos Keramidas <keramida at bytemobile.com>
Cc: FreeBSD-gnats-submit at freebsd.org
Subject: Re: bin/73112: change atol() to strtol() in badsect
Date: Fri, 29 Oct 2004 21:20:52 +0000
Giorgos Keramidas <keramida at FreeBSD.org> 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)
...
More information about the freebsd-bugs
mailing list