xfs
[Top] [All Lists]

[PATCH] Catch under/overflow cases in cvtnum() and cvttime().

To: xfs@xxxxxxxxxxx
Subject: [PATCH] Catch under/overflow cases in cvtnum() and cvttime().
From: Arkadiusz MiÅkiewicz <arekm@xxxxxxxx>
Date: Fri, 11 Jul 2014 21:34:04 +0200
Cc: Arkadiusz MiÅkiewicz <arekm@xxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maven.pl; s=maven; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=Y/qrXrsvD590C+OWSmVy4t6dgIgtZT1Wrb0LJ10n4UY=; b=YT4PYFGJJ1Fqtl5owmRGzs+7dtgrkXoJwvYLYUKtVEUhk+0bViDBfTApfZxb1LqgZS 8+ROaDBddzZaLYVSfwpoBmDg3wVOtQykut58kgDhAlF0aDoXboZA9m2SRAO7eIFSpM9T VxCZsPqHorEuGbSb9dkbWJWr6aSFLOIL14i3c=
cvtnum() and cvttime() silently ignore overflows. This leads to error
conditions not being catched. Example:

$ xfs_quota -x -c 'limit -u bsoft=987654321098765432199 \
        bhard=987654321098765432199 999' /
$

Fixed version:
$ xfs_quota -x -c 'limit -u bsoft=987654321098765432199 \
        bhard=987654321098765432199 999' /
xfs_quota: Error: could not parse size 987654321098765432199.
xfs_quota: unrecognised argument bsoft=987654321098765432199

Signed-off-by: Arkadiusz MiÅkiewicz <arekm@xxxxxxxx>
---
 libxcmd/input.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libxcmd/input.c b/libxcmd/input.c
index c06b5b8..397a124 100644
--- a/libxcmd/input.c
+++ b/libxcmd/input.c
@@ -154,6 +154,8 @@ cvtnum(
        int             c;
 
        i = strtoll(s, &sp, 0);
+       if ((i == LLONG_MIN || i == LLONG_MAX) && errno == ERANGE)
+               return -1LL;
        if (i == 0 && sp == s)
                return -1LL;
        if (*sp == '\0')
@@ -238,6 +240,8 @@ cvttime(
        char            *sp;
 
        i = strtoul(s, &sp, 0);
+       if (i == ULONG_MAX && errno == ERANGE)
+               return 0;
        if (i == 0 && sp == s)
                return 0;
        if (*sp == '\0')
-- 
2.0.0

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