IP: Use ND_ICHECKMSG_ZU() to test the header length

Output example:
  [header length 16 < 20] (invalid)

IP_HL() uses GET_U_1(), so there's no need for ND_TCHECK_*() beforehand.

Add a test file.
This commit is contained in:
Francois-Xavier Le Bail 2023-09-04 16:38:26 +02:00
parent 4c39f476df
commit eb957099ac
4 changed files with 4 additions and 5 deletions

View File

@ -341,12 +341,9 @@ ip_print(netdissect_options *ndo,
ND_ICHECK_ZU(length, <, sizeof (struct ip));
ND_ICHECKMSG_U("version", IP_V(ip), !=, 4);
ND_TCHECK_SIZE(ip);
hlen = IP_HL(ip) * 4;
if (hlen < sizeof (struct ip)) {
ND_PRINT("bad-hlen %u", hlen);
return;
}
ND_ICHECKMSG_ZU("header length", hlen, <, sizeof (struct ip));
ND_TCHECK_SIZE(ip);
len = GET_BE_U_2(ip->ip_len);
if (length < len)

View File

@ -348,6 +348,7 @@ dnssec-vv dnssec.pcap dnssec-vv.out -vv
#IPv4 tests
ipv4_invalid_length ipv4_invalid_length.pcap ipv4_invalid_length.out -v
ipv4_invalid_hdr_length ipv4_invalid_hdr_length.pcap ipv4_invalid_hdr_length.out -v
#IPv6 tests
ipv6-bad-version ipv6-bad-version.pcap ipv6-bad-version.out

View File

@ -0,0 +1 @@
1 08:57:44.621711 IP [header length 16 < 20] (invalid)

Binary file not shown.