From a9ba46856cff3ec121db5ce883defbec2d1dabd4 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 17 Apr 2016 21:22:13 +0200 Subject: wslua: fix crash on Lua errors in dissect_tcp_pdus get_len_func A similar problem was addressed in v1.99.10rc0-339-g82b2258, but that patch missed the get_pdu_len function. A crash could occur when get_pdu_len does not return a number or when it raises a Lua error. Change-Id: I1a42a95d88708ae3bf6e015ba8d7af4db5071a00 Reviewed-on: https://code.wireshark.org/review/14954 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- epan/wslua/wslua_proto.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'epan/wslua/wslua_proto.c') diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index d161ec003c..1bfacbb831 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -760,6 +760,7 @@ static guint wslua_dissect_tcp_get_pdu_len(packet_info *pinfo, tvbuff_t *tvb, int offset, void *data) { + /* WARNING: called from a TRY block, do not call luaL_error! */ func_saver_t* fs = (func_saver_t*)data; lua_State* L = fs->state; int pdu_len = 0; @@ -774,7 +775,7 @@ wslua_dissect_tcp_get_pdu_len(packet_info *pinfo, tvbuff_t *tvb, lua_pushinteger(L,offset); if ( lua_pcall(L,3,1,0) ) { - luaL_error(L, "Lua Error in dissect_tcp_pdus get_len_func: %s", lua_tostring(L,-1)); + THROW_LUA_ERROR("Lua Error in dissect_tcp_pdus get_len_func: %s", lua_tostring(L,-1)); } else { /* if the Lua dissector reported the consumed bytes, pass it to our caller */ if (lua_isnumber(L, -1)) { @@ -782,12 +783,12 @@ wslua_dissect_tcp_get_pdu_len(packet_info *pinfo, tvbuff_t *tvb, pdu_len = wslua_togint(L, -1); lua_pop(L, 1); } else { - luaL_error(L,"Lua Error dissect_tcp_pdus: get_len_func did not return a Lua number of the PDU length"); + THROW_LUA_ERROR("Lua Error dissect_tcp_pdus: get_len_func did not return a Lua number of the PDU length"); } } } else { - luaL_error(L,"Lua Error in dissect_tcp_pdus: did not find the get_len_func dissector"); + REPORT_DISSECTOR_BUG("Lua Error in dissect_tcp_pdus: did not find the get_len_func dissector"); } return pdu_len; -- cgit v1.2.3