]> The Tcpdump Group git mirrors - tcpdump/commitdiff
LISP: Add a length check
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 12 Jan 2025 21:05:02 +0000 (22:05 +0100)
committerfxlb <[email protected]>
Mon, 13 Jan 2025 06:19:33 +0000 (06:19 +0000)
Verify we have at least the header length.

Print the protocol name with nd_print_protocol_caps() before any check.
Update the lisp_type[] structure accordingly.

Add a test file with an invalid length.

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

index 4476dfff969076c8439a58b29db57c02fc1b0ad3..226f9757ce9dd3fe264b56f65b591c4ede9ac8fd 100644 (file)
@@ -128,12 +128,12 @@ enum {
 };
 
 static const struct tok lisp_type [] = {
-       { 0, "LISP-Reserved"                     },
-       { 1, "LISP-Map-Request"                  },
-       { 2, "LISP-Map-Reply"                    },
-       { 3, "LISP-Map-Register"                 },
-       { 4, "LISP-Map-Notify"                   },
-       { 8, "LISP-Encapsulated-Control-Message" },
+       { 0, "Reserved"                  },
+       { 1, "Map-Request"                       },
+       { 2, "Map-Reply"                         },
+       { 3, "Map-Register"              },
+       { 4, "Map-Notify"                        },
+       { 8, "Encapsulated-Control-Message" },
        { 0, NULL }
 };
 
@@ -245,6 +245,8 @@ lisp_print(netdissect_options *ndo, const u_char *bp, u_int length)
        const lisp_map_register_loc *lisp_loc;
 
        ndo->ndo_protocol = "lisp";
+       nd_print_protocol_caps(ndo);
+       ND_ICHECK_ZU(length, <, MAP_REGISTER_HDR_LEN);
        lisp_hdr = (const lisp_map_register_hdr *) bp;
        lisp_hdr_flag(ndo, lisp_hdr);
        /* Supporting only MAP NOTIFY and MAP REGISTER LISP packets */
@@ -406,7 +408,7 @@ static void lisp_hdr_flag(netdissect_options *ndo, const lisp_map_register_hdr *
 {
        uint8_t type = extract_lisp_type(GET_U_1(lisp_hdr->type_and_flag));
 
-       ND_PRINT("%s,", tok2str(lisp_type, "unknown-type-%u", type));
+       ND_PRINT("-%s,", tok2str(lisp_type, "unknown-type-%u", type));
        if (!ndo->ndo_vflag)
                return;
 
index 9cd74cf2132f2b1af170964820a7892a35c04d53..be8ce41be40942370482b7ee9a963b0ec0ea6298 100644 (file)
@@ -563,6 +563,7 @@ lisp_eid_register-v lisp_eid_register.pcap  lisp_eid_register-v.out -v
 lisp_ipv6_eid-v                lisp_ipv6.pcap          lisp_ipv6-v.out         -v
 lisp_invalid           lisp_invalid.pcap       lisp_invalid.out
 lisp_invalid-v         lisp_invalid.pcap       lisp_invalid-v.out      -v
+lisp_invalid_lengths  lisp_invalid_length.pcap lisp_invalid_length.out
 
 # NSH tests
 nsh                    nsh.pcap                nsh.out
diff --git a/tests/lisp_invalid_length.out b/tests/lisp_invalid_length.out
new file mode 100644 (file)
index 0000000..421e325
--- /dev/null
@@ -0,0 +1 @@
+    1  1970-01-15 05:20:00.049333 IP 13.1.1.1.61 > 1.254.1.121.4342: LISP [length 8 < 16] (invalid)
diff --git a/tests/lisp_invalid_length.pcap b/tests/lisp_invalid_length.pcap
new file mode 100644 (file)
index 0000000..931ee31
Binary files /dev/null and b/tests/lisp_invalid_length.pcap differ