Lua: allow creating TVBs after calling other (Lua) dissectors.

Don't set `lua_tvb` (or any of the other global variables) to NULL after a
Lua dissector is called: it's possible that the caller is also a Lua dissector
which may want/need that (global) variable to still be set (to the value it
had before the sub-dissector was called).

This fixes the problem reported in:
https://ask.wireshark.org/questions/56110/lua-error-tvbs-can-only-be-created-and-used-in-dissectors

Making these variables not be a globals (as suggested at the top of
init_wslua.c) might be a better solution--for another day.

Change-Id: I14fb8ec35b62abeda3f3471a323b88c80537a06e
Reviewed-on: https://code.wireshark.org/review/18095
Petri-Dish: Jeff Morriss <jeff.morriss.ws@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
Jeff Morriss 2016-10-06 10:26:27 -04:00 committed by Peter Wu
parent 3a08906ca7
commit 38682523f9
1 changed files with 12 additions and 6 deletions

View File

@ -167,6 +167,9 @@ int get_hf_wslua_text(void) {
int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_) {
int consumed_bytes = tvb_captured_length(tvb);
tvbuff_t *saved_lua_tvb = lua_tvb;
packet_info *saved_lua_pinfo = lua_pinfo;
struct _wslua_treeitem *saved_lua_tree = lua_tree;
lua_pinfo = pinfo;
lua_tvb = tvb;
@ -211,9 +214,9 @@ int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data
wmem_register_callback(pinfo->pool, lua_pinfo_end, NULL);
lua_pinfo = NULL;
lua_tree = NULL;
lua_tvb = NULL;
lua_pinfo = saved_lua_pinfo;
lua_tree = saved_lua_tree;
lua_tvb = saved_lua_tvb;
return consumed_bytes;
@ -228,6 +231,9 @@ int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data
*/
gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_) {
gboolean result = FALSE;
tvbuff_t *saved_lua_tvb = lua_tvb;
packet_info *saved_lua_pinfo = lua_pinfo;
struct _wslua_treeitem *saved_lua_tree = lua_tree;
lua_tvb = tvb;
lua_pinfo = pinfo;
@ -306,9 +312,9 @@ gboolean heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, v
wmem_register_callback(pinfo->pool, lua_pinfo_end, NULL);
lua_pinfo = NULL;
lua_tree = NULL;
lua_tvb = NULL;
lua_pinfo = saved_lua_pinfo;
lua_tree = saved_lua_tree;
lua_tvb = saved_lua_tvb;
return result;
}