From 4a70bf7021cfccda890be7cee92aef0fc3fbab72 Mon Sep 17 00:00:00 2001
From: John Thacker <johnthacker@gmail.com>
Date: Mon, 13 Apr 2026 16:28:10 -0400
Subject: [PATCH] GSM RP: Don't use a global

Call proto_tree_get_parent_tree, which does the same thing as currently
when the protocol is dissected normally through the RP dissector, but
also works properly when rp_data_n_ms is called directly, e.g. by the
BSSMAP dissector.

Fix #21189

(This is a case where it's actually more likely to crash with the normal
wmem than with WIRESHARK_DEBUG_WMEM_OVERRIDE=simple.)

AI-Assisted: no


(cherry picked from commit 6fc954bbb3b19f9b49c0905442c81b26611fa202)

Co-authored-by: John Thacker <johnthacker@gmail.com>
---
 epan/dissectors/packet-gsm_a_rp.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Index: wireshark-3.6.24/epan/dissectors/packet-gsm_a_rp.c
===================================================================
--- wireshark-3.6.24.orig/epan/dissectors/packet-gsm_a_rp.c
+++ wireshark-3.6.24/epan/dissectors/packet-gsm_a_rp.c
@@ -90,8 +90,6 @@ static dissector_handle_t gsm_a_dtap_han
 
 static int proto_json = -1;
 
-static proto_tree *g_tree;
-
 #define	NUM_GSM_RP_ELEM (sizeof(gsm_rp_elem_strings)/sizeof(value_string))
 gint ett_gsm_rp_elem[NUM_GSM_RP_ELEM];
 
@@ -150,7 +148,7 @@ de_rp_user_data(tvbuff_t *tvb, proto_tre
 	 */
 	tpdu_tvb = tvb_new_subset_length(tvb, curr_offset, len);
 
-	call_dissector_only(gsm_sms_handle, tpdu_tvb, pinfo, g_tree, NULL);
+	call_dissector_only(gsm_sms_handle, tpdu_tvb, pinfo, proto_tree_get_parent_tree(tree), NULL);
 
 	curr_offset += len;
 
@@ -428,8 +426,6 @@ dissect_rp(tvbuff_t *tvb, packet_info *p
 	offset = 0;
 	saved_offset = offset;
 
-	g_tree = tree;
-
 	len = tvb_reported_length(tvb);
 
 	/*
