]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix integer parsing in cli (#2003)
authorPhilip Jones <philj56@gmail.com>
Tue, 18 Feb 2020 23:30:59 +0000 (15:30 -0800)
committerGitHub <noreply@github.com>
Tue, 18 Feb 2020 23:30:59 +0000 (15:30 -0800)
programs/zstdcli.c

index 3ebecadcab2ae0fcdba722ed0c8db19d12c20483..ce431e6c9ed56e6798b33e2172c5af9eefc43cd2 100644 (file)
@@ -254,10 +254,12 @@ static int readU32FromCharChecked(const char** stringPtr, unsigned* value)
 {
     unsigned result = 0;
     while ((**stringPtr >='0') && (**stringPtr <='9')) {
-        unsigned const max = (((unsigned)(-1)) / 10) - 1;
+        unsigned const max = ((unsigned)(-1)) / 10;
+        unsigned last = result;
         if (result > max) return 1; /* overflow error */
         result *= 10;
         result += (unsigned)(**stringPtr - '0');
+        if (result < last) return 1; /* overflow error */
         (*stringPtr)++ ;
     }
     if ((**stringPtr=='K') || (**stringPtr=='M')) {