]> The Tcpdump Group git mirrors - tcpdump/commit
Fix two undefined behaviors for the pcap_loop() call
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 8 Dec 2024 22:08:52 +0000 (23:08 +0100)
committerfxlb <[email protected]>
Tue, 10 Dec 2024 03:58:04 +0000 (03:58 +0000)
commitdc1b49b1f6864a0cbe58bb203634763fb26aa8d1
treeb75a4cee828b78b9e14271052092593125df920a
parent7b422ef14bccea8b61e9073c904cf67d14bc4275
Fix two undefined behaviors for the pcap_loop() call

Limit the --skip argument to INT_MAX.
Limit the sum of -c and --skip arguments to INT_MAX.

Fix the regression in 3eab64d3: The '--skip 0' option is allowed to get
the first packet in some loop e.g. in a shell script.

The errors were:

tcpdump.c:2696:8: runtime error: implicit conversion from type 'int' of
  value -1 (32-bit, signed) to type 'u_int' (aka 'unsigned int')
  changed the value to 4294967295 (32-bit, unsigned)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcpdump.c:2696:8

tcpdump.c:2696:8: runtime error: implicit conversion from type 'u_int'
  (aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type
  'int' changed the value to -1 (32-bit, signed)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcpdump.c:2696:8
tcpdump.c