xfs
[Top] [All Lists]

[PATCH V2] libxcmd: return error from cvtnum() on overflow

To: Eric Sandeen <sandeen@xxxxxxxxxx>
Subject: [PATCH V2] libxcmd: return error from cvtnum() on overflow
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Mon, 28 Feb 2011 15:26:58 -0600
Cc: xfs-oss <xfs@xxxxxxxxxxx>
In-reply-to: <4D6C075F.1010509@xxxxxxxxxx>
References: <4D6C075F.1010509@xxxxxxxxxx>
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7
Test 071 was failing in weird ways, partly because it was trying
to pass in offsets larger than strtoll() could accept, which then
silently returned LLONG_MAX instead.  For DIO tests, this was
unaligned, so we got unexpected (to me, anyay) alignment errors.

At least printing out the perror() makes this more obvious,
but unfortunately we then get the somewhat odd output:

# xfs_io -f -d -c "pwrite 9223373136366403584  4096" /mnt/test/grrr
cvtnum: Numerical result out of range
non-numeric offset argument -- 9223373136366403584

Test 071 still fails, but at least it's a bit more obvious as to why.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---

V2: zero errno first so we don't pick up a stale errno.

Note:
... should I change all callsites from "non-numeric" to "invalid" perhaps?

diff --git a/libxcmd/input.c b/libxcmd/input.c
index d7f29c1..c2bc4a0 100644
--- a/libxcmd/input.c
+++ b/libxcmd/input.c
@@ -152,7 +152,12 @@ cvtnum(
        char            *sp;
        int             c;
 
+       errno = 0;
        i = strtoll(s, &sp, 0);
+       if (errno == ERANGE) {
+               perror("cvtnum");
+               return -1LL;
+       }
        if (i == 0 && sp == s)
                return -1LL;
        if (*sp == '\0')


<Prev in Thread] Current Thread [Next in Thread>