From: Francois-Xavier Le Bail Date: Tue, 17 Nov 2020 20:14:51 +0000 (+0100) Subject: SLL/SLL2: Use ND_TCHECK_LEN() for bounds checks X-Git-Tag: tcpdump-4.99-bp~56 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/ab5a18ab1312d37e1aceded9960a97a23028235a SLL/SLL2: Use ND_TCHECK_LEN() for bounds checks Moreover: Define ND_LONGJMP_FROM_TCHECK. Remove 2 ndo_ll_hdr_len increments in truncation cases. Remove 2 comments: "can't happen" is wrong (fuzzing, etc.) --- diff --git a/print-sll.c b/print-sll.c index ad0ae7f1..19d2973e 100644 --- a/print-sll.c +++ b/print-sll.c @@ -31,6 +31,7 @@ #include "netdissect-stdinc.h" +#define ND_LONGJMP_FROM_TCHECK #include "netdissect.h" #include "addrtoname.h" #include "ethertype.h" @@ -223,16 +224,7 @@ sll_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char u_int hdrlen; ndo->ndo_protocol = "sll"; - if (caplen < SLL_HDR_LEN) { - /* - * XXX - this "can't happen" because "pcap-linux.c" always - * adds this many bytes of header to every packet in a - * cooked socket capture. - */ - nd_print_trunc(ndo); - ndo->ndo_ll_hdr_len += caplen; - return; - } + ND_TCHECK_LEN(p, SLL_HDR_LEN); sllp = (const struct sll_header *)p; @@ -419,16 +411,7 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char #endif ndo->ndo_protocol = "sll2"; - if (caplen < SLL2_HDR_LEN) { - /* - * XXX - this "can't happen" because "pcap-linux.c" always - * adds this many bytes of header to every packet in a - * cooked socket capture. - */ - nd_print_trunc(ndo); - ndo->ndo_ll_hdr_len += caplen; - return; - } + ND_TCHECK_LEN(p, SLL2_HDR_LEN); sllp = (const struct sll2_header *)p; #ifdef HAVE_NET_IF_H