]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Ethernet: Rework the length checks
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 21 Nov 2021 14:33:24 +0000 (15:33 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 28 Nov 2021 13:53:47 +0000 (14:53 +0100)
Add a sanity check: packet length need to be >= capture length

(Like a sanity check in print.c, pretty_print_packet() function)

Remove a now useless test:
Because packet length (length) >= capture length (caplen), when
caplen >= ETHER_HDRLEN + switch_tag_len, length cannot
be < ETHER_HDRLEN + switch_tag_len.

(cherry picked from commit d52b757efa7b0678e34c0ffe32d1c0da29bbb604)

print-ether.c

index da95862b3c0b5150a4b324f0439caf4eb828f395..e1d5db21dddb0134681af6265f2c3913fd1a76c0 100644 (file)
@@ -150,14 +150,15 @@ ether_common_print(netdissect_options *ndo, const u_char *p, u_int length,
        int llc_hdrlen;
        struct lladdr_info src, dst;
 
+       if (length < caplen) {
+               ND_PRINT("[length %u < caplen %u]", length, caplen);
+               nd_print_invalid(ndo);
+               return length;
+       }
        if (caplen < ETHER_HDRLEN + switch_tag_len) {
                nd_print_trunc(ndo);
                return caplen;
        }
-       if (length < ETHER_HDRLEN + switch_tag_len) {
-               nd_print_trunc(ndo);
-               return length;
-       }
 
        if (print_encap_header != NULL)
                (*print_encap_header)(ndo, encap_header_arg);