]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Introduce and use ND_LONGJMP_FROM_TCHECK.
authorDenis Ovsienko <[email protected]>
Sun, 27 Sep 2020 20:43:16 +0000 (21:43 +0100)
committerDenis Ovsienko <[email protected]>
Sun, 27 Sep 2020 20:45:46 +0000 (21:45 +0100)
Apply this to the 4 the recently converted protocols.

HOW TO USE:

Define this in a print-*.c file before including netdissect.h to make
all its ND_TCHECK*() instances longjmp(). Only do this after verifying
that every ND_TCHECK*() in the file is correct and that in every
possible case it is safe to call longjmp() without incurring resource
leaks or any other problems. If it is not safe or feasible to convert
whole file, consider converting one function at a time.

netdissect.h
print-ahcp.c
print-aoe.c
print-loopback.c
print-openflow-1.0.c
print-openflow.c

index 3b9aaf4b8f016e07e47a7bfa6fa9b13c58d0a489..b87b76a7cd2fbc396fe391ecdc3099c7b11a610c 100644 (file)
@@ -362,7 +362,11 @@ extern void nd_pop_all_packet_info(netdissect_options *);
 #define ND_TTEST_SIZE(p) ND_TTEST_LEN(p, sizeof(*(p)))
 
 /* Bail out if "l" bytes from "p" were not captured */
+#ifdef ND_LONGJMP_FROM_TCHECK
+#define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) nd_trunc(ndo)
+#else
 #define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) goto trunc
+#endif
 
 /* Bail out if "*(p)" was not captured */
 #define ND_TCHECK_SIZE(p) ND_TCHECK_LEN(p, sizeof(*(p)))
index 8529b8602e37cf0c9a1886ed163f3a82648cbb9a..9859f76009d5953efffb8a0d9c2c60d4bcd23879 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
@@ -118,9 +119,6 @@ ahcp_time_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -135,9 +133,6 @@ ahcp_seconds_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -159,9 +154,6 @@ ahcp_ipv6_addresses_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -183,9 +175,6 @@ ahcp_ipv4_addresses_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -207,9 +196,6 @@ ahcp_ipv6_prefixes_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -231,9 +217,6 @@ ahcp_ipv4_prefixes_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -291,9 +274,6 @@ ahcp1_options_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -338,9 +318,7 @@ ahcp1_body_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
+
 }
 
 void
@@ -407,7 +385,4 @@ ahcp_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
index 558eeae2fa8e29bc71accb22a6be4e5b7422b163..41f54b99380936e768532f8ce7784ba2353012eb 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
@@ -198,9 +199,6 @@ aoev1_issue_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -244,9 +242,6 @@ aoev1_query_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -297,9 +292,6 @@ aoev1_mac_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -333,9 +325,6 @@ aoev1_reserve_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* cp points to the Ver/Flags octet */
@@ -392,9 +381,6 @@ aoev1_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 void
@@ -423,8 +409,5 @@ aoe_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
index e9d0b1a298a71748b11d7722baa5926d5b4e6cd0..ee0caf3cfe4f3ab4e97564bf6a5500d6dc04b220 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
@@ -98,9 +99,6 @@ loopback_message_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 void
@@ -133,8 +131,5 @@ loopback_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
index 557d1e9c2ecfb4436759de7c654dcef88df428d9..567a89533ff73068b9452a03d798f9dd58fca21c 100644 (file)
@@ -14,7 +14,7 @@
  * The convention is that a printer function returns iff the given structure is
  * completely within the packet buffer; otherwise it processes the part that is
  * within the buffer, sooner of later takes the "truncated packet" shortcut via
- * nd_trunc() and never returns. With that in mind, the function may return
+ * longjmp() and never returns. With that in mind, the function may return
  * without printing the structure completely if it is invalid or the ndo_vflag
  * value is not high enough. This way the calling function can try to decode
  * the next data item.
@@ -65,6 +65,7 @@
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
@@ -735,10 +736,6 @@ of10_data_print(netdissect_options *ndo,
                hex_and_ascii_print(ndo, "\n\t  ", cp, len);
        else
                ND_TCHECK_LEN(cp, len);
-       return;
-
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -919,9 +916,6 @@ of10_bsn_message_print(netdissect_options *ndo,
 invalid: /* skip the undersized data */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -986,9 +980,6 @@ of10_bsn_actions_print(netdissect_options *ndo,
 invalid:
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -1014,9 +1005,6 @@ of10_vendor_action_print(netdissect_options *ndo,
 invalid: /* skip the undersized data */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -1042,9 +1030,6 @@ of10_vendor_message_print(netdissect_options *ndo,
 invalid: /* skip the undersized data */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* Vendor ID is mandatory, data is optional. */
@@ -1067,9 +1052,6 @@ of10_vendor_data_print(netdissect_options *ndo,
 invalid: /* skip the undersized data */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 static void
@@ -1088,10 +1070,6 @@ of10_packet_data_print(netdissect_options *ndo,
        ND_PRINT(", frame decoding below\n");
        ether_print(ndo, cp, len, ND_BYTES_AVAILABLE_AFTER(cp), NULL, NULL);
        ndo->ndo_vflag += 3;
-       return;
-
-trunc:
-       nd_trunc(ndo);
 }
 
 /* [OF10] Section 5.2.1 */
@@ -1149,9 +1127,6 @@ of10_phy_ports_print(netdissect_options *ndo,
 invalid: /* skip the undersized trailing data */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* [OF10] Section 5.2.2 */
@@ -1219,9 +1194,6 @@ of10_queue_props_print(netdissect_options *ndo,
 invalid: /* skip the rest of queue properties */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* ibid */
@@ -1258,9 +1230,6 @@ of10_queues_print(netdissect_options *ndo,
 invalid: /* skip the rest of queues */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* [OF10] Section 5.2.3 */
@@ -1349,10 +1318,6 @@ of10_match_print(netdissect_options *ndo,
        }
        else
                ND_TCHECK_2(cp);
-       return;
-
-trunc:
-       nd_trunc(ndo);
 }
 
 /* [OF10] Section 5.2.4 */
@@ -1514,9 +1479,6 @@ of10_actions_print(netdissect_options *ndo,
 invalid: /* skip the rest of actions */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* [OF10] Section 5.3.1 */
@@ -1621,10 +1583,6 @@ of10_port_mod_print(netdissect_options *ndo,
        /* pad */
        /* Always the last field, check bounds. */
        ND_TCHECK_4(cp);
-       return;
-
-trunc:
-       nd_trunc(ndo);
 }
 
 /* [OF10] Section 5.3.5 */
@@ -1700,9 +1658,6 @@ of10_stats_request_print(netdissect_options *ndo,
 invalid: /* skip the message body */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* ibid */
@@ -1741,9 +1696,6 @@ of10_desc_stats_reply_print(netdissect_options *ndo,
 invalid: /* skip the message body */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* ibid */
@@ -1806,9 +1758,6 @@ of10_flow_stats_reply_print(netdissect_options *ndo,
 invalid: /* skip the rest of flow statistics entries */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* ibid */
@@ -1835,9 +1784,6 @@ of10_aggregate_stats_reply_print(netdissect_options *ndo,
 invalid: /* skip the message body */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* ibid */
@@ -1881,9 +1827,6 @@ of10_table_stats_reply_print(netdissect_options *ndo,
 invalid: /* skip the undersized trailing data */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* ibid */
@@ -1946,9 +1889,6 @@ of10_port_stats_reply_print(netdissect_options *ndo,
 invalid: /* skip the undersized trailing data */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* ibid */
@@ -1983,9 +1923,6 @@ of10_queue_stats_reply_print(netdissect_options *ndo,
 invalid: /* skip the undersized trailing data */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* ibid */
@@ -2020,10 +1957,6 @@ of10_stats_reply_print(netdissect_options *ndo,
                }
        }
        ND_TCHECK_LEN(cp, len);
-       return;
-
-trunc:
-       nd_trunc(ndo);
 }
 
 /* [OF10] Section 5.3.6 */
@@ -2054,9 +1987,6 @@ of10_packet_out_print(netdissect_options *ndo,
 invalid: /* skip the rest of the message body */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
 
 /* [OF10] Section 5.4.1 */
@@ -2083,10 +2013,6 @@ of10_packet_in_print(netdissect_options *ndo,
        OF_CHK_FWD(1);
        /* data */
        of10_packet_data_print(ndo, cp, len);
-       return;
-
-trunc:
-       nd_trunc(ndo);
 }
 
 /* [OF10] Section 5.4.2 */
@@ -2356,7 +2282,4 @@ invalid: /* skip the message body */
        nd_print_invalid(ndo);
 next_message:
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }
index 3b85dd7a9e7c369cd2e25fd14c90753948f24358..f56b0a35882ad779ac353af8e81e5d59107633ba 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 #include "openflow.h"
@@ -152,7 +153,4 @@ openflow_print(netdissect_options *ndo, const u_char *cp, u_int len)
 invalid: /* fail the current packet */
        nd_print_invalid(ndo);
        ND_TCHECK_LEN(cp, len);
-       return;
-trunc:
-       nd_trunc(ndo);
 }