diff --git a/epan/dissectors/packet-dhcpv6.c b/epan/dissectors/packet-dhcpv6.c index 8bab66504e..30173f4151 100644 --- a/epan/dissectors/packet-dhcpv6.c +++ b/epan/dissectors/packet-dhcpv6.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -329,6 +330,8 @@ static dissector_table_t dhcpv6_enterprise_opts_dissector_table; #define DHCPV6_LEASEDURATION_INFINITY 0xffffffff #define HOP_COUNT_LIMIT 32 +#define MAX_RECURSION_DEPTH 10 // Arbitrarily chosen. + /********************************************************************************************/ /********************************** MESSAGE TYPES *******************************************/ /********************************************************************************************/ @@ -1843,6 +1846,7 @@ cablelabs_fmt_dpoe_server_version( gchar *result, guint32 revision ) /* Returns the number of bytes consumed by this option. */ static int +// NOLINTNEXTLINE(misc-no-recursion) dhcpv6_option(tvbuff_t *tvb, packet_info *pinfo, proto_tree *bp_tree, int off, int eoff, gboolean *at_end, int protocol, hopcount_info hpi, guint8 msgtype) { @@ -1883,6 +1887,10 @@ dhcpv6_option(tvbuff_t *tvb, packet_info *pinfo, proto_tree *bp_tree, proto_tree_add_item(subtree, hf_option_length, tvb, off + 2, 2, ENC_BIG_ENDIAN); off += 4; + unsigned recursion_depth = p_get_proto_depth(pinfo, proto_dhcpv6); + DISSECTOR_ASSERT(recursion_depth <= MAX_RECURSION_DEPTH); + p_set_proto_depth(pinfo, proto_dhcpv6, recursion_depth + 1); + switch (opttype) { case OPTION_CLIENTID: if (optlen > 0) { @@ -2949,12 +2957,15 @@ dhcpv6_option(tvbuff_t *tvb, packet_info *pinfo, proto_tree *bp_tree, break; } + p_set_proto_depth(pinfo, proto_dhcpv6, recursion_depth); + return 4 + optlen; } -/* May be called recursively */ +/* May be called recursively via dhcpv6_option */ static void +// NOLINTNEXTLINE(misc-no-recursion) dissect_dhcpv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int off, int eoff, hopcount_info hpi) {