Date: Mon, 25 Oct 2004 15:04:44 +0300 (EEST) From: Giorgos Keramidas <keramida@FreeBSD.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/73112: change atol() to strtol() in badsect Message-ID: <200410251204.i9PC4iKl003336@orion.daedalusnetworks.priv> Resent-Message-ID: <200410251210.i9PCALBs091345@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 73112 >Category: bin >Synopsis: change atol() to strtol() in badsect >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Oct 25 12:10:21 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Giorgos Keramidas >Release: FreeBSD 6.0-CURRENT i386 >Organization: >Environment: System: FreeBSD orion.daedalusnetworks.priv 6.0-CURRENT FreeBSD 6.0-CURRENT #4: \ Fri Oct 22 17:12:12 EEST 2004 root@orion.daedalusnetworks.priv:/usr/obj/usr/src/sys/ORION i386 >Description: 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. >How-To-Repeat: >Fix: --- badsect.patch begins here --- 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 @@ -59,6 +59,7 @@ #include <ufs/ffs/fs.h> #include <err.h> +#include <errno.h> #include <dirent.h> #include <fcntl.h> #include <libufs.h> @@ -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); if (chkuse(number, 1)) continue; /* --- badsect.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200410251204.i9PC4iKl003336>