opnsense-src/sbin/ipfw
John Baldwin 9148904343 ipfw: Fix broken length checks on routing messages
Subtracting unsigned and signed types of the same rank yields an
unsigned value that is never less than 0.  Rewrite the checks to use
the pattern of 'if (msglen < <desired size>)' instead of
'if (msglen - <desired_size> < 0)' to avoid the subtraction.

To avoid adding lots of casts to appease -Wsign-compare, use a
separate ssize_t variable for the return value of read(2) and convert
msglen to size_t.

While here, fix the first check against the size of the route message
header which was inverted and would have rejected all valid messages
if not for the unsigned vs signed bug causing all of the checks to be
broken.

sbin/ipfw/ipfw2.c: In function 'ipfw_rtsock_monitor':
sbin/ipfw/ipfw2.c:6088:43: error: comparison of unsigned expression in '< 0' is always false [-Werror=type-limits]
 6088 |                 if (sizeof(*hdr) - msglen < 0)
      |                                           ^

Reported by:	GCC -Wtype-limits
Fixes:		3c76623ad5 ("ipfw: add 'internal monitor' subcommand to capture rtsock messages.")
2025-04-21 22:00:14 -04:00
..
tests ipfw: add state/comment tests 2023-06-16 07:24:19 +00:00
altq.c Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
dummynet.c ipfw: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0]) 2024-04-28 21:30:55 -06:00
ipfw.8 ipfw: add 'internal monitor' subcommand to capture rtsock messages. 2025-04-18 15:22:56 +03:00
ipfw2.c ipfw: Fix broken length checks on routing messages 2025-04-21 22:00:14 -04:00
ipfw2.h ipfw: add 'internal monitor' subcommand to capture rtsock messages. 2025-04-18 15:22:56 +03:00
ipv6.c Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
main.c ipfw : Enable support for EIM NAT 2024-12-06 09:18:09 +00:00
Makefile Remove residual blank line at start of Makefile 2024-07-15 16:43:39 -06:00
Makefile.depend Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
nat.c ipfw : Enable support for EIM NAT 2024-12-06 09:18:09 +00:00
nat64clat.c sbin: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
nat64lsn.c ipfw: migrate ipfw to 32-bit size rule numbers 2025-03-03 21:15:17 +03:00
nat64stl.c sbin: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
nptv6.c sbin: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
tables.c ipfw: migrate ipfw to 32-bit size rule numbers 2025-03-03 21:15:17 +03:00