Lua: Remove heur dissectors when reload Lua plugins

When reloading Lua plugins all registered heuristic dissectors
must be removed.

Bug: 12251
Change-Id: Ib7da6df347fb9294f5394ae531b582bf6d2730bb
Reviewed-on: https://code.wireshark.org/review/14429
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
This commit is contained in:
Stig Bjørlykke 2016-03-11 20:54:26 +01:00
parent b46d55551f
commit 6f220a343e
4 changed files with 21 additions and 2 deletions

View File

@ -2261,14 +2261,15 @@ heur_dissector_delete(const char *name, heur_dissector_t dissector, const int pr
g_assert(sub_dissectors != NULL);
hdtbl_entry.dissector = dissector;
hdtbl_entry.protocol = find_protocol_by_id(proto);
found_entry = g_slist_find_custom(sub_dissectors->dissectors,
(gpointer) &hdtbl_entry, find_matching_heur_dissector);
if (found_entry) {
g_free(((heur_dtbl_entry_t *)(found_entry->data))->list_name);
heur_dtbl_entry_t *found_hdtbl_entry = (heur_dtbl_entry_t *)(found_entry->data);
g_free(found_hdtbl_entry->list_name);
g_hash_table_remove(heuristic_short_names, (gpointer)found_hdtbl_entry->short_name);
g_slice_free(heur_dtbl_entry_t, found_entry->data);
sub_dissectors->dissectors = g_slist_delete_link(sub_dissectors->dissectors,
found_entry);

View File

@ -978,6 +978,7 @@ void wslua_reload_plugins (register_cb cb, gpointer client_data) {
if (ops->close_dialogs)
ops->close_dialogs();
wslua_deregister_heur_dissectors(L);
wslua_deregister_protocols(L);
wslua_deregister_dissector_tables(L);
wslua_deregister_listeners(L);

View File

@ -783,6 +783,7 @@ extern int luaopen_rex_glib(lua_State *L);
extern const gchar* get_current_plugin_version(void);
extern void clear_current_plugin_version(void);
extern int wslua_deregister_heur_dissectors(lua_State* L);
extern int wslua_deregister_protocols(lua_State* L);
extern int wslua_deregister_dissector_tables(lua_State* L);
extern int wslua_deregister_listeners(lua_State* L);

View File

@ -583,6 +583,22 @@ ProtoField wslua_is_field_available(lua_State* L, const char* field_abbr) {
return NULL;
}
int wslua_deregister_heur_dissectors(lua_State* L) {
/* for each registered heur dissector do... */
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_heur_dissectors_table_ref);
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
const gchar *listname = luaL_checkstring(L, -2);
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
const gchar *proto_name = luaL_checkstring(L, -2);
int proto_id = proto_get_id_by_short_name(proto_name);
heur_dissector_delete(listname, heur_dissect_lua, proto_id);
}
}
lua_pop(L, 1); /* lua_heur_dissectors_table_ref */
return 0;
}
int wslua_deregister_protocols(lua_State* L) {
/* for each registered Proto protocol do... */
lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref);