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,
      | ^
```
This commit is contained in:
Gerald Combs 2024-02-22 18:29:49 -08:00
parent 1515b211e2
commit 5a04c4ecee
1 changed files with 12 additions and 1 deletions

View File

@ -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)
{