]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add sanity checks on packet header (packet length / capture length)
authorFrancois-Xavier Le Bail <[email protected]>
Mon, 15 Jan 2018 13:39:40 +0000 (14:39 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Tue, 16 Jan 2018 07:32:52 +0000 (08:32 +0100)
For a valid packet:
packet length != 0,
capture length != 0,
packet length >= capture length.

Update the output of some tests accordingly.

netdissect.h
print.c
tests/hncp_dhcpv4data-oobr.out
tests/icmp6_mobileprefix_asan.out
tests/olsr-oobr-2.out
tests/pim_header_asan-2.out
tests/rpki-rtr-oob.out
tests/rx_ubik-oobr.out
tests/vtp_asan.out

index 4c902f1b05c0591de55530879a4a600fc146bd2d..5d81daae1dd7544d4c791b5f2120c635cd3ffe72 100644 (file)
@@ -195,6 +195,7 @@ struct netdissect_options {
                                 * LF, CR and SPACE as graphical chars
                                 */
   int ndo_Hflag;               /* dissect 802.11s draft mesh standard */
+  int ndo_invalid_header;
   int ndo_packet_number;       /* print a packet number in the beginning of line */
   int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */
   int ndo_tstamp_precision;    /* requested time stamp precision */
diff --git a/print.c b/print.c
index ca231f146e01f24837adb36fa8b6b60d933b43c5..36eceec38270f2bdb7ccf9789cafba76bf48c753 100644 (file)
--- a/print.c
+++ b/print.c
@@ -317,6 +317,30 @@ pretty_print_packet(netdissect_options *ndo, const struct pcap_pkthdr *h,
        if(ndo->ndo_packet_number)
                ND_PRINT("%5u  ", packets_captured);
 
+       /* Sanity checks on packet length / capture length */
+       ndo->ndo_invalid_header = 0;
+       if(h->caplen == 0) {
+               ndo->ndo_invalid_header = 1;
+               ND_PRINT("[Invalid header: caplen==0");
+       }
+       if (h->len == 0) {
+               if (!ndo->ndo_invalid_header) {
+                       ndo->ndo_invalid_header = 1;
+                       ND_PRINT("[Invalid header:");
+               } else
+                       ND_PRINT(",");
+               ND_PRINT(" len==0");
+       } else if (h->len < h->caplen) {
+               if (!ndo->ndo_invalid_header) {
+                       ndo->ndo_invalid_header = 1;
+                       ND_PRINT("[Invalid header:");
+               } else
+                       ND_PRINT(",");
+               ND_PRINT(" len(%u) < caplen(%u)", h->len, h->caplen);
+       }
+       if (ndo->ndo_invalid_header)
+               ND_PRINT("] ");
+
        ts_print(ndo, &h->ts);
 
        /*
index 7d558dd9d16e16a263b6f7690df9c92b4d0b802e..15f3db430183c4fff083c1f193150b03b1727e8d 100644 (file)
@@ -1,4 +1,4 @@
-IP truncated-ip - 260 bytes missing! (tos 0x12,ECT(0), ttl 48, id 21323, offset 0, flags [+, DF, rsvd], proto UDP (17), length 296, bad cksum 8e0f (->cd08)!)
+[Invalid header: len(50) < caplen(79)] IP truncated-ip - 260 bytes missing! (tos 0x12,ECT(0), ttl 48, id 21323, offset 0, flags [+, DF, rsvd], proto UDP (17), length 296, bad cksum 8e0f (->cd08)!)
     1.2.7.0.1812 > 128.253.0.96.8231: hncp (268)
        DHCPv4-Data (6)
                DNS-server (98) (invalid)
index 0e0d97c3418e7414456465005a8f18001bf5a90c..1c4fec49e283e66e708bca7f364d1868af639674 100644 (file)
@@ -1,2 +1,2 @@
 IP6 (class 0x50, flowlabel 0x0002c, hlim 0, next-header ICMPv6 (58) payload length: 7168) 4f:f829:c:1a1a:1a1a:1a1a:1a37:0 > 16:0:400:0:64fb:9303:f293:8200: ICMP6, mobile router advertisement, length 7168, id 0x9393[|icmp6]
-[|ether]
+[Invalid header: caplen==0, len==0] [|ether]
index c2d4a8fe32bc55cc0a0a3b528dbc9a9ef91e2756..ad4055c8289f174d50f5f5e7022e26de3253c6b2 100644 (file)
@@ -1,3 +1,3 @@
-[|ether]
-[|ether]
+[Invalid header: caplen==0] [|ether]
+[Invalid header: caplen==0] [|ether]
 IP6 (flowlabel 0x06400, hlim 0, next-header UDP (17) payload length: 5401) 0:24::1e:a0a:141e.698 > 38fd:7f49:eaff:ffff:2025:7373:7562:2573.2: OLSRv6, seq 0x0201, length 5393[|olsr]
index 576a8b7fa090b6417796c87f9e56572f6b133f23..26d8e0fec2e522751f3d55a593e0a0e589eab575 100644 (file)
@@ -1,5 +1,5 @@
 IP6 (class 0x76, flowlabel 0xf6767, hlim 109, next-header PIM (103) payload length: 13927) 6767:ff:ffff:ff67:6767:6778:6767:6767 > 6700:7f:e664:24:2424:2424:2424:25eb: PIMv2, length 13927
        Register, RFC2117-encoding, cksum 0x4e23 (unverified), Flags [ none ]
        [|pim]
-[|ether]
-[|ether]
+[Invalid header: caplen==0] [|ether]
+[Invalid header: len==0] [|ether]
index 19bbdc26269a198c4124d4dd6091f1b93eee0a36..6102fedd2fca19a51e89d8700e042ec8b6bdf91e 100644 (file)
@@ -1,3 +1,3 @@
-IP truncated-ip - 22 bytes missing! (tos 0x0, ttl 254, id 13327, offset 0, flags [+, DF, rsvd], proto TCP (6), length 62, bad cksum 8e7f (->c283)!)
+[Invalid header: len(54) < caplen(64)] IP truncated-ip - 22 bytes missing! (tos 0x0, ttl 254, id 13327, offset 0, flags [+, DF, rsvd], proto TCP (6), length 62, bad cksum 8e7f (->c283)!)
     19.128.128.20.323 > 76.19.6.127.49600: Flags [none], seq 2684354563:2684354585, win 28672, length 22
        RPKI-RTRv171 (unknown)
index f192432d4ae8d4eb1381bf5b5896d1a25c5ddab3..c742855d366ee5cbfa05f9938b2283952f93fd90 100644 (file)
@@ -1 +1 @@
-IP truncated-ip - 2598 bytes missing! 222.241.104.198.3503 > 131.63.241.146.7002:  rx data pt ubik call disk-lock tid 50266112.32382 file 2122216448 pos 545160708 length 1087685554 [|ubik] (2632)
+[Invalid header: len(76) < caplen(94)] IP truncated-ip - 2598 bytes missing! 222.241.104.198.3503 > 131.63.241.146.7002:  rx data pt ubik call disk-lock tid 50266112.32382 file 2122216448 pos 545160708 length 1087685554 [|ubik] (2632)
index 17b682bf6b7f23335ed4bb7d150627db5911259b..0a576cad3845d335d46962d107219ebf07667636 100644 (file)
@@ -1,6 +1,6 @@
 FRF.16 Frag, seq 193, Flags [Begin, End], UI 08! VTPv69, Message Subset advertisement (0x02), length 2126400013
        Domain name: , Seq number: 0[|vtp]
-[|mfr]
-[|mfr]
-[|mfr]
-[|mfr]
+[Invalid header: caplen==0] [|mfr]
+[Invalid header: caplen==0, len==0] [|mfr]
+[Invalid header: caplen==0, len==0] [|mfr]
+[Invalid header: caplen==0, len==0] [|mfr]