aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2024-02-21 11:53:18 -0800
committerGerald Combs <gerald@wireshark.org>2024-02-21 20:27:07 +0000
commit282bd19e887a56496011d14b1bf7bdde40f9216e (patch)
treeaa68c22e367667d3a591ea4f0b26b9055a4d2c59
parentf8af3cd41051c0d140be8706a0d961f39f9ed914 (diff)
TN5250: Add a recursion check
-rw-r--r--epan/dissectors/packet-tn5250.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/epan/dissectors/packet-tn5250.c b/epan/dissectors/packet-tn5250.c
index 7f4039b01a..96f352358a 100644
--- a/epan/dissectors/packet-tn5250.c
+++ b/epan/dissectors/packet-tn5250.c
@@ -21,6 +21,7 @@
#include "config.h"
#include <epan/packet.h>
+#include <epan/proto_data.h>
#include <epan/expert.h>
#include <epan/conversation.h>
#include "packet-tn5250.h"
@@ -40,6 +41,8 @@ typedef struct tn5250_conv_info_t {
#define NEGATIVE_RESPONSE3 0x100501
#define NEGATIVE_RESPONSE4 0x100502
+#define MAX_RECURSION_DEPTH 10 // Arbitrarily chosen.
+
static const value_string vals_tn5250_negative_responses[] = {
{ 0x08110200, "The Cancel key of a printer was pressed when it was not in an error state"},
{ 0x08110201, "The Cancel key of a printer was pressed when it was in an error state"},
@@ -4917,6 +4920,7 @@ dissect_tn5250_data_until_next_command(proto_tree *tn5250_tree, tvbuff_t *tvb, g
#endif
static guint32
+// NOLINTNEXTLINE(misc-no-recursion)
dissect_outbound_stream(proto_tree *tn5250_tree, packet_info *pinfo, tvbuff_t *tvb, gint offset)
{
gint command_code;
@@ -4964,7 +4968,11 @@ dissect_outbound_stream(proto_tree *tn5250_tree, packet_info *pinfo, tvbuff_t *t
break;
case RESTORE_SCREEN:
while (tvb_reported_length_remaining(tvb, offset) > 0) {
+ unsigned recursion_depth = p_get_proto_depth(pinfo, proto_tn5250);
+ DISSECTOR_ASSERT(recursion_depth <= MAX_RECURSION_DEPTH);
+ p_set_proto_depth(pinfo, proto_tn5250, recursion_depth + 1);
offset += dissect_outbound_stream(cc_tree, pinfo, tvb, offset);
+ p_set_proto_depth(pinfo, proto_tn5250, recursion_depth);
}
break;
case WRITE_ERROR_CODE_TO_WINDOW: