Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ping: Fix integer overflow for high -s values
a647e2c commit increased value max allowed -s value from 127992 to INT_MAX (2147483647). To have space for this range datalen was changed from signed int to size_t, but it forgot to change other int variables which also work with this data (hold, packlen). This fixes signed integer overflow: $ export CC="clang" $ export CFLAGS="-O0 -g -fsanitize=address,undefined" $ export LDFLAGS="-O0 -g -fsanitize=address,undefined" $ ./configure && make $ ./builddir/ping/ping -s 2147483647 ::1 ../ping/ping6_common.c:317:7: runtime error: signed integer overflow: -2147483641 + -1174404560 cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../ping/ping6_common.c:317:7 ./builddir/ping/ping: WARNING: probably, rcvbuf is not enough to hold preload PING ::1 (::1) 2147483647 data bytes $ ./builddir/ping/ping -s 2147483647 127.0.0.1 ../ping/ping.c:997:7: runtime error: signed integer overflow: -2147483641 + -1090518520 cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../ping/ping.c:997:7 ./builddir/ping/ping: WARNING: probably, rcvbuf is not enough to hold preload PING 127.0.0.1 (127.0.0.1) 2147483647(2147483675) bytes of data. NOTE: I'm not sure if it makes sense to allow -s higher than 65507 (IPv4) or 65527 (IPv6) - more than these is over limit for IPv4/IPv6 packet payload. It would have to be sent as multiple packets (IPv4 fragmentation, IPv6 next_header packet chain or jumbo extension header). IMHO it never worked. That is probably the reason, why other implementations (busybox, fping, inetutils) limit data size to <= 65535. Fixes: a647e2c ("ping: allow any package size to be defined by user") Fixes: iputils#542 Reported-by: mimicria Suggested-by: Marius Tomaschewski <[email protected]> Signed-off-by: Petr Vorel <[email protected]>
- Loading branch information