]> The Tcpdump Group git mirrors - tcpdump/commitdiff
IPv6: Report some invalid packets as invalid, not truncated
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 25 Aug 2023 14:39:59 +0000 (16:39 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 25 Aug 2023 17:03:43 +0000 (19:03 +0200)
When the (original) length is < length of the header, output example:
  [length 39 < 40] (invalid)
(The IPv6 header must be 40 bytes in length.)

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

Add a test file.

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

index 285fc97981a84ab32e967d59e61e53190992663c..93308a2c333bd2b27ac72902c6743cd21567a293 100644 (file)
@@ -246,17 +246,13 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                ND_PRINT(" ");
        }
 
+       ND_ICHECK_ZU(length, <, sizeof (struct ip6_hdr));
        if (IP6_VERSION(ip6) != 6) {
                ND_PRINT("version error: %u != 6", IP6_VERSION(ip6));
                return;
        }
 
        ND_TCHECK_SIZE(ip6);
-       if (length < sizeof (struct ip6_hdr)) {
-               ND_PRINT("truncated-ip6 %u", length);
-               return;
-       }
-
        payload_len = GET_BE_U_2(ip6->ip6_plen);
        /*
         * RFC 1883 says:
@@ -501,4 +497,8 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
        return;
 trunc:
        nd_print_trunc(ndo);
+       return;
+
+invalid:
+       nd_print_invalid(ndo);
 }
index db01e6fd3c5cff841142534400666c516af5d075..5d114bd0782431c5910fb568cfbd4c6678937ae4 100644 (file)
@@ -359,6 +359,7 @@ ipv6-srh-tlv-hmac ipv6-srh-tlv-hmac.pcap ipv6-srh-tlv-hmac.out
 ipv6-srh-tlv-hmac-v ipv6-srh-tlv-hmac.pcap ipv6-srh-tlv-hmac-v.out -v
 ipv6-srh-tlv-pad1-padn-5 ipv6-srh-tlv-pad1-padn-5.pcap ipv6-srh-tlv-pad1-padn-5.out
 ipv6-srh-tlv-pad1-padn-5-v ipv6-srh-tlv-pad1-padn-5.pcap ipv6-srh-tlv-pad1-padn-5-v.out -v
+ipv6_invalid_length ipv6_invalid_length.pcap ipv6_invalid_length.out
 
 # Loopback/CTP test case
 loopback       loopback.pcap           loopback.out
diff --git a/tests/ipv6_invalid_length.out b/tests/ipv6_invalid_length.out
new file mode 100644 (file)
index 0000000..60a7274
--- /dev/null
@@ -0,0 +1 @@
+    1  09:18:26.706088 IP6  [length 39 < 40] (invalid)
diff --git a/tests/ipv6_invalid_length.pcap b/tests/ipv6_invalid_length.pcap
new file mode 100644 (file)
index 0000000..f0fef23
Binary files /dev/null and b/tests/ipv6_invalid_length.pcap differ