From e2c0fd75e48a3cbf1bf48b8afe28fff50d8e0877 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 12 Jul 2022 16:12:40 -0700 Subject: Linux USB: check the captured length early in the fixup process. In fixup_pcap_pkthdr(), check th capture length to make sure it has a full header before we start looking at fields in the header. The other place that calls fix_linux_usb_mmapped_length() already ensures that we have at least a full USB metadata header; this change means that both places that call it do, so we can remove the check from fix_linux_usb_mmapped_length() itself. --- pcap-usb-linux-common.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'pcap-usb-linux-common.c') diff --git a/pcap-usb-linux-common.c b/pcap-usb-linux-common.c index d5d9e538..6bd044c9 100644 --- a/pcap-usb-linux-common.c +++ b/pcap-usb-linux-common.c @@ -41,13 +41,11 @@ fix_linux_usb_mmapped_length(struct pcap_pkthdr *pkth, const u_char *bp) const pcap_usb_header_mmapped *hdr; u_int bytes_left; + /* + * All callers of this routine must ensure that pkth->caplen is + * >= sizeof (pcap_usb_header_mmapped). + */ bytes_left = pkth->caplen; - if (bytes_left < sizeof (pcap_usb_header_mmapped)) { - /* - * We don't have the full metadata header, so give up. - */ - return; - } bytes_left -= sizeof (pcap_usb_header_mmapped); hdr = (const pcap_usb_header_mmapped *) bp; -- cgit v1.2.3