bin/73112: change atol() to strtol() in badsect
Giorgos Keramidas
keramida at FreeBSD.org
Mon Oct 25 05:10:22 PDT 2004
>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 at 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:
More information about the freebsd-bugs
mailing list