X-Spam-Checker-Version: SpamAssassin 3.3.0-rupdated (updated) on oss.sgi.com X-Spam-Level: *** X-Spam-Status: No, score=3.4 required=5.0 tests=AWL,BAYES_00,FH_DATE_PAST_20XX, HEADER_ESQ,J_CHICKENPOX_43,J_CHICKENPOX_75,UNPARSEABLE_RELAY autolearn=no version=3.3.0-rupdated Received: from cuda.sgi.com (cuda2.sgi.com [192.48.176.25]) by oss.sgi.com (8.14.3/8.14.3/SuSE Linux 0.8) with ESMTP id o3K5Kg9F004961 for ; Tue, 20 Apr 2010 00:20:43 -0500 X-ASG-Debug-ID: 1271740961-6df002b90000-NocioJ X-Barracuda-URL: http://cuda.sgi.com:80/cgi-bin/mark.cgi Received: from rcsinet10.oracle.com (localhost [127.0.0.1]) by cuda.sgi.com (Spam Firewall) with ESMTP id 093DC2D63D1 for ; Mon, 19 Apr 2010 22:22:41 -0700 (PDT) Received: from rcsinet10.oracle.com (rcsinet10.oracle.com [148.87.113.121]) by cuda.sgi.com with ESMTP id pVKC0x1H7Y6zesq3 for ; Mon, 19 Apr 2010 22:22:41 -0700 (PDT) Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o3K5MNQA015531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 20 Apr 2010 05:22:24 GMT Received: from acsmt355.oracle.com (acsmt355.oracle.com [141.146.40.155]) by acsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o3K4JS3V008890; Tue, 20 Apr 2010 05:22:22 GMT Received: from abhmt008.oracle.com by acsmt355.oracle.com with ESMTP id 189856021271740876; Mon, 19 Apr 2010 22:21:16 -0700 Received: from wenwang.oracle.com (/141.144.145.236) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 19 Apr 2010 22:21:14 -0700 Received: by wenwang.oracle.com (sSMTP sendmail emulation); Tue, 20 Apr 2010 13:20:28 +0800 Date: Tue, 20 Apr 2010 13:20:28 +0800 From: Wengang Wang To: Dave Chinner Cc: Wengang Wang , greg.marsden@oracle.com, joe.jin@oracle.com, xfs@oss.sgi.com X-ASG-Orig-Subj: Re: [PATCH] xfsprogs: mkfs: make strict check on -ialign option Subject: Re: [PATCH] xfsprogs: mkfs: make strict check on -ialign option Message-ID: <20100420052028.GC2494@laptop.oracle.com> References: <201004190942.o3J7aqh5003810@rcsinet13.oracle.com> <20100420034533.GB15130@dastard> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100420034533.GB15130@dastard> User-Agent: Mutt/1.5.20 (2009-08-17) X-Auth-Type: Internal IP X-Source-IP: acsinet15.oracle.com [141.146.126.227] X-CT-RefId: str=0001.0A090201.4BCD3A11.0120:SCFMA922111,ss=1,fgs=0 X-Barracuda-Connect: rcsinet10.oracle.com[148.87.113.121] X-Barracuda-Start-Time: 1271740962 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Virus-Scanned: by cuda.sgi.com at sgi.com X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using per-user scores of TAG_LEVEL=2.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=2.1 tests=UNPARSEABLE_RELAY X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.27930 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-Virus-Scanned: ClamAV version 0.94.2, clamav-milter version 0.94.2 on oss.sgi.com X-Virus-Status: Clean On 10-04-20 13:45, Dave Chinner wrote: > On Mon, Apr 19, 2010 at 05:41:36PM +0800, Wengang Wang wrote: > > Though it's clearly said in mkfs.xfs man page that for -ialign option only 1 or > > 0 are valid values, I would like to make a strict check on it in code. > > > > If a user specified -ialign=y(but he meant -ialign=1 actually), mkfs treats "y" > > as "0"(simply by atoi()) thus acts wrongly without complaint. I think we'd better > > prevent that from happening, so I made the patch. The patch fails the operation > > on values for -ialign option, like "yes", "no", "y", "n". > > > > Signed-off-by: Wengang Wang > > --- > > mkfs/xfs_mkfs.c | 7 +++++-- > > 1 files changed, 5 insertions(+), 2 deletions(-) > > > > diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c > > index 2d09e36..d7e9eb3 100644 > > --- a/mkfs/xfs_mkfs.c > > +++ b/mkfs/xfs_mkfs.c > > @@ -1180,14 +1180,17 @@ main( > > p = optarg; > > while (*p != '\0') { > > char *value; > > + int len; > > > > switch (getsubopt(&p, (constpp)iopts, &value)) { > > case I_ALIGN: > > if (!value) > > value = "1"; > > - iaflag = atoi(value); > > - if (iaflag < 0 || iaflag > 1) > > + len = strlen(value); > > + if (len != 1 || value[0] < '0' || > > + value[0] > '1') > > illegal(value, "i align"); > > + iaflag = value[0] - '0'; > > Wouldn't this be better changing atoi() to strtol() and then checking > errno along with the bounds? Hi Dave, I tested strtol() with some cases, result is like the following: -- errno: "12" -- 12 errno: 0 "yes" -- 0 errno: 0 "no" -- 0 errno: 0 "y" -- 0 errno: 0 "" -- 0 errno: 0 "0" -- 0 errno: 0 "1" -- 1 errno: 0 It can't tell the original string is "yes", "no", "y", "" or "0" for returning zero with errno being "OK". That is not the result I want. regards, wengang.