aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-dhcpv6.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2024-02-22 18:29:49 -0800
committerGerald Combs <gerald@wireshark.org>2024-02-23 03:26:34 +0000
commit5a04c4ecee4a40851c8fd0f7de0ee96d257bb752 (patch)
tree9c531731be68d0889ca66f83e2612bf2ac633c05 /epan/dissectors/packet-dhcpv6.c
parent1515b211e20354e097092de0b52e50862e64ce36 (diff)
DHCPv6: Add a recursion check
Fix ``` wireshark/epan/dissectors/packet-dhcpv6.c:1846:1: warning: function 'dhcpv6_option' is within a recursive call chain [misc-no-recursion] 1846 | dhcpv6_option(tvbuff_t *tvb, packet_info *pinfo, proto_tree *bp_tree, | ^ wireshark/epan/dissectors/packet-dhcpv6.c:1846:1: note: example recursive call chain, starting from function 'dhcpv6_option' wireshark/epan/dissectors/packet-dhcpv6.c:2052:28: note: Frame #1: function 'dhcpv6_option' calls function 'dhcpv6_option' here: 2052 | temp_optlen += dhcpv6_option(tvb, pinfo, subtree, | ^ wireshark/epan/dissectors/packet-dhcpv6.c:2052:28: note: ... which was the starting point of the recursive call chain; there may be other cycles wireshark/epan/dissectors/packet-dhcpv6.c:2958:1: warning: function 'dissect_dhcpv6' is within a recursive call chain [misc-no-recursion] 2958 | dissect_dhcpv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, | ^ ```
Diffstat (limited to 'epan/dissectors/packet-dhcpv6.c')
-rw-r--r--epan/dissectors/packet-dhcpv6.c13
1 files changed, 12 insertions, 1 deletions
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 <epan/addr_resolv.h>
#include <epan/expert.h>
#include <epan/prefs.h>
+#include <epan/proto_data.h>
#include <epan/arptypes.h>
#include <epan/sminmpec.h>
#include <epan/strutil.h>
@@ -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)
{