]> The Tcpdump Group git mirrors - tcpdump/commitdiff
RESP: Fix overflow check.
authorGuy Harris <[email protected]>
Wed, 15 Feb 2017 23:43:46 +0000 (15:43 -0800)
committerDenis Ovsienko <[email protected]>
Wed, 13 Sep 2017 11:25:44 +0000 (12:25 +0100)
At that point, result is a multiple of 10, so it can at most be
2147483640, i.e. (INT_MAX / 10)*10.

If it's less than that, you can add any value between 0 and 9 to it and
it won't overflow.

If it's *equal* to that, you can only add a value between 0 and 7
without overflowing, i.e. the maximum is INT_MAX % 10.

Addresses Coverity CID 1400557.

print-resp.c

index bec8b6da237ee9c856c64ab7d99acc427d9be56f..cc7212411377298eb8f6711d7d39e8e405369db7 100644 (file)
@@ -493,7 +493,7 @@ resp_get_length(netdissect_options *ndo, register const u_char *bp, int len, con
             too_large = 1;
         } else {
             result *= 10;
-            if (result == INT_MAX && c > (INT_MAX % 10)) {
+            if (result == ((INT_MAX / 10) * 10) && c > (INT_MAX % 10)) {
                 /* This will overflow an int when we add c */
                 too_large = 1;
             } else