From: Philip Jones Date: Tue, 18 Feb 2020 23:30:59 +0000 (-0800) Subject: Fix integer parsing in cli (#2003) X-Git-Tag: v1.4.5^2~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e728e26ca6a8b10404d733b4892c31d97677689;p=thirdparty%2Fzstd.git Fix integer parsing in cli (#2003) --- diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 3ebecadca..ce431e6c9 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -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')) {