From keramida@bytemobile.com  Mon Oct 25 11:08:12 2004
Return-Path: <keramida@bytemobile.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 374AC16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 25 Oct 2004 11:08:12 +0000 (GMT)
Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.27])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 74C8843D45
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 25 Oct 2004 11:08:11 +0000 (GMT)
	(envelope-from keramida@bytemobile.com)
Received: from orion.daedalusnetworks.priv (aris.bedc.ondsl.gr [62.103.39.226])
	by kane.otenet.gr (8.13.1/8.13.1/Debian-15.OTEnet.1) with SMTP id i9PB7wN7020762
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 25 Oct 2004 14:08:05 +0300
Received: from orion.daedalusnetworks.priv (orion [127.0.0.1])
	by orion.daedalusnetworks.priv (8.13.1/8.13.1) with ESMTP id i9PB7ubn002482
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 25 Oct 2004 14:07:56 +0300 (EEST)
	(envelope-from keramida@orion.daedalusnetworks.priv)
Received: (from keramida@localhost)
	by orion.daedalusnetworks.priv (8.13.1/8.13.1/Submit) id i9PB7tZ2002481;
	Mon, 25 Oct 2004 14:07:55 +0300 (EEST)
	(envelope-from keramida)
Message-Id: <200410251107.i9PB7tZ2002481@orion.daedalusnetworks.priv>
Date: Mon, 25 Oct 2004 14:07:55 +0300 (EEST)
From: Giorgos Keramidas <keramida@freebsd.org>
Reply-To: Giorgos Keramidas <keramida@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ffsinfo conversion from atol() to strtol()
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         73110
>Category:       bin
>Synopsis:       [patch] ffsinfo conversion from atol() to strtol()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    rwatson
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 25 11:10:14 GMT 2004
>Closed-Date:    Sun Jan 13 16:11:42 UTC 2008
>Last-Modified:  Sun Jan 13 16:11:42 UTC 2008
>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 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:
State-Changed-From-To: open->patched 
State-Changed-By: rwatson 
State-Changed-When: Mon Jan 3 18:58:09 GMT 2005 
State-Changed-Why:  
Applied as ffsinfo.c:1.7 in FreeBSD CVS HEAD.  Will MFC after two weeks. 
Thanks! 



Responsible-Changed-From-To: freebsd-bugs->rwatson 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Mon Jan 3 18:58:09 GMT 2005 
Responsible-Changed-Why:  
Grab ownership of this PR. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=73110 
State-Changed-From-To: patched->closed 
State-Changed-By: rwatson 
State-Changed-When: Sun Jan 13 16:11:30 UTC 2008 
State-Changed-Why:  
Patch was applied. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=73110 
>Unformatted:
