]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/timeutils: (parse_timestamp_reference) report errors on overflow
authorThomas Weißschuh <thomas@t-8ch.de>
Sun, 24 Sep 2023 21:43:44 +0000 (23:43 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 24 Sep 2023 21:44:36 +0000 (23:44 +0200)
Instead of silently returning '0' on 'minus'-underflow and silently
wrapping on 'plus'-overflow return ERANGE.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/timeutils.c

index 3ed506a7df3535e1dcdcd3bc44e6ebbbdca7c30e..b791c3f4826cc417d3c3c3d2ab59d7b93548d206 100644 (file)
@@ -373,11 +373,13 @@ static int parse_timestamp_reference(time_t x, const char *t, usec_t *usec)
 
        ret += (usec_t) x * USEC_PER_SEC;
 
+       if (minus > ret)
+               return -ERANGE;
+       if ((ret + plus) < ret)
+               return -ERANGE;
+
        ret += plus;
-       if (ret > minus)
-               ret -= minus;
-       else
-               ret = 0;
+       ret -= minus;
 
        *usec = ret;