]> The Tcpdump Group git mirrors - tcpdump/commitdiff
IP: Report an invalid case as invalid, not truncated
authorFrancois-Xavier Le Bail <[email protected]>
Mon, 4 Sep 2023 07:27:48 +0000 (09:27 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Wed, 25 Oct 2023 12:37:35 +0000 (14:37 +0200)
When the (original) length is < length of the header, output example:
  [length 19 < 20] (invalid)
(The minimal IPv4 header must be 20 bytes in length.)

Place the 'length' test before the 'version' test.

Add a test file.

(cherry picked from commit 4c39f476dfd20e6815bcc38df51294ce96a73b28)

print-ip.c
tests/TESTLIST
tests/ipv4_invalid_length.out [new file with mode: 0644]
tests/ipv4_invalid_length.pcap [new file with mode: 0644]

index 37c30e5e5fa0f45c91d04ddfacd7ea66b1f68c5a..fab8e0b798ae6a602b959bf90964b8741204d47e 100644 (file)
@@ -338,13 +338,10 @@ ip_print(netdissect_options *ndo,
                ND_PRINT(" ");
        }
 
+       ND_ICHECK_ZU(length, <, sizeof (struct ip));
        ND_ICHECKMSG_U("version", IP_V(ip), !=, 4);
 
        ND_TCHECK_SIZE(ip);
-       if (length < sizeof (struct ip)) {
-               ND_PRINT("truncated-ip %u", length);
-               return;
-       }
        hlen = IP_HL(ip) * 4;
        if (hlen < sizeof (struct ip)) {
                ND_PRINT("bad-hlen %u", hlen);
index 3b4afec2dcbbea6dccea408bc1c81a7774d30a11..639fa95c5d2cca49e9a85bbd7ef1beb16a23bc94 100644 (file)
@@ -304,6 +304,9 @@ dns_udp_8053-T dns_udp_8053.pcap dns_udp_8053-T.out -vv -T domain
 # DNSSEC from https://bugzilla.redhat.com/show_bug.cgi?id=205842, -vv exposes EDNS DO
 dnssec-vv      dnssec.pcap             dnssec-vv.out           -vv
 
+#IPv4 tests
+ipv4_invalid_length ipv4_invalid_length.pcap ipv4_invalid_length.out -v
+
 #IPv6 tests
 ipv6-bad-version       ipv6-bad-version.pcap   ipv6-bad-version.out
 ipv6-routing-header    ipv6-routing-header.pcap        ipv6-routing-header.out -v
diff --git a/tests/ipv4_invalid_length.out b/tests/ipv4_invalid_length.out
new file mode 100644 (file)
index 0000000..000b92e
--- /dev/null
@@ -0,0 +1 @@
+    1  14:57:25.640485 IP  [length 19 < 20] (invalid)
diff --git a/tests/ipv4_invalid_length.pcap b/tests/ipv4_invalid_length.pcap
new file mode 100644 (file)
index 0000000..dca5f72
Binary files /dev/null and b/tests/ipv4_invalid_length.pcap differ