bin/73110: ffsinfo conversion from atol() to strtol()

Giorgos Keramidas keramida at FreeBSD.org
Mon Oct 25 04:10:15 PDT 2004


>Number:         73110
>Category:       bin
>Synopsis:       ffsinfo conversion from atol() to strtol()
>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 11:10:14 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 ffsinfo utility uses atol() to parse numeric values out of optarg strings.
This isn't necessarily a bug, but it can be slightly inconvenient, because
atol() doesn't know how to parse hexadecimal or octal numbers and at least one
of the options of ffsinfo(8) would be easier to use if it did.

Changing atol() -> strtol() allows one to use hex masks for -l MASK, i.e.:

orion:/a/freebsd/src/sbin/ffsinfo# ./ffsinfo -l 0x3ff /

A word of caution: the source of ffsinfo.c does not follow style(9).  This is
why I used a style similar to the one of the original source in my diff.

>How-To-Repeat:
>Fix:

--- ffsinfo.patch begins here ---
Index: ffsinfo.c
===================================================================
RCS file: /home/ncvs/src/sbin/ffsinfo/ffsinfo.c,v
retrieving revision 1.7
diff -u -u -r1.7 ffsinfo.c
--- ffsinfo.c	26 Jul 2004 15:04:57 -0000	1.7
+++ ffsinfo.c	25 Oct 2004 11:02:19 -0000
@@ -63,6 +63,7 @@
 
 #include <ctype.h>
 #include <err.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <libufs.h>
 #include <paths.h>
@@ -148,19 +149,25 @@
 	while ((ch=getopt(argc, argv, "g:i:l:o:")) != -1) {
 		switch(ch) {
 		case 'g':
-			cfg_cg=atol(optarg);
+			cfg_cg=strtol(optarg, NULL, 0);
+			if(errno == EINVAL||errno == ERANGE)
+				err(1, "%s", optarg);
 			if(cfg_cg < -1) {
 				usage();
 			}
 			break;
 		case 'i':
-			cfg_in=atol(optarg);
+			cfg_in=strtol(optarg, NULL, 0);
+			if(errno == EINVAL||errno == ERANGE)
+				err(1, "%s", optarg);
 			if(cfg_in < 0) {
 				usage();
 			}
 			break; 
 		case 'l':
-			cfg_lv=atol(optarg);
+			cfg_lv=strtol(optarg, NULL, 0);
+			if(errno == EINVAL||errno == ERANGE)
+				err(1, "%s", optarg);
 			if(cfg_lv < 0x1||cfg_lv > 0x3ff) {
 				usage();
 			}
--- ffsinfo.patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list