2006-09-25 01:09:00 +00:00
|
|
|
/*
|
2015-07-07 15:30:44 +00:00
|
|
|
* wslua_proto.c
|
2006-09-25 01:09:00 +00:00
|
|
|
*
|
|
|
|
* wireshark's interface to the Lua Programming Language
|
|
|
|
*
|
2008-08-05 21:03:46 +00:00
|
|
|
* (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
|
2007-05-02 23:39:44 +00:00
|
|
|
* (c) 2007, Tamas Regos <tamas.regos@ericsson.com>
|
2015-08-11 12:08:08 +00:00
|
|
|
* (c) 2014, Stig Bjorlykke <stig@bjorlykke.org>
|
2006-09-25 01:09:00 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-08 16:33:09 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2006-09-25 01:09:00 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-21 13:13:39 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2015-07-07 15:30:44 +00:00
|
|
|
#include "wslua.h"
|
|
|
|
#include <epan/dissectors/packet-tcp.h>
|
wslua: fix crash when a LUA error is raised in TRY block
The dissect_tcp_pdus function in LUA is passed two LUA functions that
get the PDU length and the dissect a PDU. When one of these functions
fail, a longjmp is made to the the caller of lua_pcall.
This is no problem for the PDU length function, but the PDU dissect
function is wrapped in a TRY/CATCH/ENDTRY block which also uses longjmp
and need to be fully executed. Without doing so, LUA exceptions will
crash on a weird location (except_pop).
Fix the crash by not using luaL_error, but throw dissector errors which
properly breaks out of the tcp_dissect_pdus C function and then convert
it to a LUA error such that the dissector can handle it.
Test with `tshark -X lua_script:crash.lua -r ssl.pcap`:
trivial_proto = Proto("trivial", "Trivial Protocol")
function dissect_foo(tvb, pinfo, tree)
error("triggering a LUA error");
end
function get_pdu_len(tvb, pinfo, tree) return 5; end
function trivial_proto.dissector(tvb, pinfo, tree)
dissect_tcp_pdus(tvb, tree, 5, get_pdu_len, dissect_foo)
end
tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(443, trivial_proto)
It should not crash and will print this:
Lua Error: dissect_tcp_pdus dissect_func: [string "crash.lua"]:3: triggering a LUA error
Change-Id: Ibd079cc5eb3a2e4d2e62ea49a512fa2cc8e561ea
Reviewed-on: https://code.wireshark.org/review/10685
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Evan Huus <eapache@gmail.com>
2015-09-29 10:20:07 +00:00
|
|
|
#include <epan/exceptions.h>
|
2015-07-07 15:30:44 +00:00
|
|
|
|
2020-03-30 15:57:16 +00:00
|
|
|
/* WSLUA_MODULE Proto Functions For New Protocols And Dissectors
|
2014-03-23 15:01:12 +00:00
|
|
|
|
2020-03-29 22:46:46 +00:00
|
|
|
The classes and functions in this chapter allow Lua scripts to create new protocols for Wireshark.
|
|
|
|
<<lua_class_Proto,`Proto`>> protocol objects can have <<lua_class_Pref,`Pref`>> preferences, <<lua_class_ProtoField,`ProtoField`>> fields for filterable values that can be displayed in a details view tree, functions for dissecting the new protocol, and so on.
|
|
|
|
|
2020-03-30 15:57:16 +00:00
|
|
|
The dissection function can be hooked into existing protocol tables through <<lua_class_DissectorTable,`DissectorTable`>> so that the new protocol dissector function gets called by that protocol, and the new dissector can itself call on other, already existing protocol dissectors by retrieving and calling the <<lua_class_Dissector,`Dissector`>> object.
|
2020-03-29 22:46:46 +00:00
|
|
|
A <<lua_class_Proto,`Proto`>> dissector can also be used as a post-dissector, at the end of every frame's dissection, or as a heuristic dissector.
|
2014-03-23 15:01:12 +00:00
|
|
|
*/
|
2006-10-18 18:45:24 +00:00
|
|
|
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2015-07-07 15:30:44 +00:00
|
|
|
/*
|
|
|
|
* _func_saver stores function refs so that Lua won't garbage collect them prematurely.
|
|
|
|
* It is only used by tcp_dissect_pdus right now.
|
|
|
|
*/
|
|
|
|
typedef struct _func_saver {
|
|
|
|
lua_State* state;
|
|
|
|
int get_len_ref;
|
|
|
|
int dissect_ref;
|
|
|
|
} func_saver_t;
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2015-07-07 15:30:44 +00:00
|
|
|
static GPtrArray* outstanding_FuncSavers = NULL;
|
2014-03-08 23:57:04 +00:00
|
|
|
|
2015-07-07 15:30:44 +00:00
|
|
|
void clear_outstanding_FuncSavers(void) {
|
|
|
|
while (outstanding_FuncSavers->len) {
|
|
|
|
func_saver_t* fs = (func_saver_t*)g_ptr_array_remove_index_fast(outstanding_FuncSavers,0);
|
|
|
|
if (fs->state) {
|
|
|
|
lua_State* L = fs->state;
|
|
|
|
if (fs->get_len_ref != LUA_NOREF) {
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, fs->get_len_ref);
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
2015-07-07 15:30:44 +00:00
|
|
|
if (fs->dissect_ref != LUA_NOREF) {
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, fs->dissect_ref);
|
2013-12-20 13:33:48 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-07 15:30:44 +00:00
|
|
|
g_free(fs);
|
2014-03-25 22:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-03 08:58:44 +00:00
|
|
|
WSLUA_CLASS_DEFINE(Proto,FAIL_ON_NULL("Proto"));
|
2006-09-25 01:09:00 +00:00
|
|
|
/*
|
2020-03-29 22:46:46 +00:00
|
|
|
A new protocol in Wireshark.
|
|
|
|
Protocols have several uses.
|
|
|
|
The main one is to dissect a protocol, but they can also be dummies used to register preferences for other purposes.
|
2006-09-25 01:09:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int protocols_table_ref = LUA_NOREF;
|
|
|
|
|
2020-03-29 22:46:46 +00:00
|
|
|
WSLUA_CONSTRUCTOR Proto_new(lua_State* L) { /* Creates a new <<lua_class_Proto,`Proto`>> object. */
|
2014-03-23 15:01:12 +00:00
|
|
|
#define WSLUA_ARG_Proto_new_NAME 1 /* The name of the protocol. */
|
|
|
|
#define WSLUA_ARG_Proto_new_DESC 2 /* A Long Text description of the protocol (usually lowercase). */
|
2009-01-27 14:36:46 +00:00
|
|
|
const gchar* name = luaL_checkstring(L,WSLUA_ARG_Proto_new_NAME);
|
|
|
|
const gchar* desc = luaL_checkstring(L,WSLUA_ARG_Proto_new_DESC);
|
2014-10-12 20:27:54 +00:00
|
|
|
Proto proto;
|
|
|
|
gchar *loname, *hiname;
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-02-21 02:12:25 +00:00
|
|
|
/* TODO: should really make a common function for all of wslua that does checkstring and non-empty at same time */
|
2014-10-12 20:27:54 +00:00
|
|
|
if (!name[0]) {
|
|
|
|
WSLUA_ARG_ERROR(Proto_new,NAME,"must not be an empty string");
|
|
|
|
return 0;
|
|
|
|
}
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2014-10-12 20:27:54 +00:00
|
|
|
if (!desc[0]) {
|
|
|
|
WSLUA_ARG_ERROR(Proto_new,DESC,"must not be an empty string");
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2015-11-20 17:56:45 +00:00
|
|
|
if (proto_name_already_registered(desc)) {
|
|
|
|
WSLUA_ARG_ERROR(Proto_new,DESC,"there cannot be two protocols with the same description");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-12 20:27:54 +00:00
|
|
|
loname = g_ascii_strdown(name, -1);
|
2015-11-20 17:56:45 +00:00
|
|
|
if (proto_check_field_name(loname)) {
|
|
|
|
g_free(loname);
|
2016-03-31 19:52:11 +00:00
|
|
|
WSLUA_ARG_ERROR(Proto_new,NAME,"invalid character in name");
|
2015-11-20 17:56:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2015-11-20 17:56:45 +00:00
|
|
|
hiname = g_ascii_strup(name, -1);
|
|
|
|
if ((proto_get_id_by_short_name(hiname) != -1) ||
|
|
|
|
(proto_get_id_by_filter_name(loname) != -1))
|
|
|
|
{
|
2014-10-12 20:27:54 +00:00
|
|
|
g_free(loname);
|
2015-11-20 17:56:45 +00:00
|
|
|
g_free(hiname);
|
2016-03-31 19:52:11 +00:00
|
|
|
WSLUA_ARG_ERROR(Proto_new,NAME,"there cannot be two protocols with the same name");
|
2014-10-12 20:27:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-03-25 22:11:05 +00:00
|
|
|
|
2020-12-21 02:30:28 +00:00
|
|
|
proto = g_new(wslua_proto_t, 1);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-10-12 20:27:54 +00:00
|
|
|
proto->name = hiname;
|
2014-10-31 12:21:46 +00:00
|
|
|
proto->loname = loname;
|
2014-10-12 20:27:54 +00:00
|
|
|
proto->desc = g_strdup(desc);
|
|
|
|
proto->hfid = proto_register_protocol(proto->desc,hiname,loname);
|
|
|
|
proto->ett = -1;
|
|
|
|
proto->is_postdissector = FALSE;
|
2015-08-11 12:08:08 +00:00
|
|
|
proto->expired = FALSE;
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-10-12 20:27:54 +00:00
|
|
|
lua_newtable (L);
|
|
|
|
proto->fields = luaL_ref(L, LUA_REGISTRYINDEX);
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2014-10-12 20:27:54 +00:00
|
|
|
lua_newtable (L);
|
|
|
|
proto->expert_info_table_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
proto->expert_module = expert_register_protocol(proto->hfid);
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2014-10-12 20:27:54 +00:00
|
|
|
proto->prefs.name = NULL;
|
|
|
|
proto->prefs.label = NULL;
|
|
|
|
proto->prefs.desc = NULL;
|
|
|
|
proto->prefs.value.u = 0;
|
|
|
|
proto->prefs.next = NULL;
|
|
|
|
proto->prefs.proto = proto;
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-10-12 20:27:54 +00:00
|
|
|
proto->prefs_module = NULL;
|
|
|
|
proto->handle = NULL;
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-10-12 20:27:54 +00:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref);
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2014-10-12 20:27:54 +00:00
|
|
|
lua_pushstring(L,loname);
|
|
|
|
pushProto(L,proto);
|
|
|
|
|
|
|
|
lua_settable(L, -3);
|
|
|
|
|
|
|
|
pushProto(L,proto);
|
|
|
|
|
2020-03-29 22:46:46 +00:00
|
|
|
WSLUA_RETURN(1); /* The newly created <<lua_class_Proto,`Proto`>> object. */
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 22:46:46 +00:00
|
|
|
WSLUA_METAMETHOD Proto__call(lua_State* L) { /* Creates a <<lua_class_Proto,`Proto`>> object. */
|
2014-03-23 15:01:12 +00:00
|
|
|
#define WSLUA_ARG_Proto__call_NAME 1 /* The name of the protocol. */
|
|
|
|
#define WSLUA_ARG_Proto__call_DESC 2 /* A Long Text description of the protocol (usually lowercase). */
|
2014-02-19 08:22:55 +00:00
|
|
|
lua_remove(L,1); /* remove the table */
|
2020-03-29 22:46:46 +00:00
|
|
|
WSLUA_RETURN(Proto_new(L)); /* The new <<lua_class_Proto,`Proto`>> object. */
|
2014-02-19 08:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int Proto__tostring(lua_State* L) {
|
2006-09-25 01:09:00 +00:00
|
|
|
Proto proto = checkProto(L,1);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-12-29 05:21:15 +00:00
|
|
|
lua_pushfstring(L, "Proto: %s", proto->name);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2006-09-25 01:09:00 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-10-21 12:41:15 +00:00
|
|
|
WSLUA_FUNCTION wslua_register_postdissector(lua_State* L) {
|
2020-03-29 22:46:46 +00:00
|
|
|
/* Make a <<lua_class_Proto,`Proto`>> protocol (with a dissector function) a post-dissector.
|
2014-03-23 15:01:12 +00:00
|
|
|
It will be called for every frame after dissection. */
|
|
|
|
#define WSLUA_ARG_register_postdissector_PROTO 1 /* the protocol to be used as post-dissector. */
|
|
|
|
#define WSLUA_OPTARG_register_postdissector_ALLFIELDS 2 /* Whether to generate all fields.
|
2018-02-09 20:56:58 +00:00
|
|
|
Note: This impacts performance (default=false). */
|
2014-02-21 06:11:41 +00:00
|
|
|
|
2009-01-27 14:36:46 +00:00
|
|
|
Proto proto = checkProto(L,WSLUA_ARG_register_postdissector_PROTO);
|
2014-02-21 06:11:41 +00:00
|
|
|
const gboolean all_fields = wslua_optbool(L, WSLUA_OPTARG_register_postdissector_ALLFIELDS, FALSE);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2006-09-25 01:09:00 +00:00
|
|
|
if(!proto->is_postdissector) {
|
|
|
|
if (! proto->handle) {
|
2015-12-11 01:56:03 +00:00
|
|
|
proto->handle = register_dissector(proto->loname, dissect_lua, proto->hfid);
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2006-09-25 01:09:00 +00:00
|
|
|
register_postdissector(proto->handle);
|
2014-10-31 12:25:14 +00:00
|
|
|
proto->is_postdissector = TRUE;
|
2006-09-25 01:09:00 +00:00
|
|
|
} else {
|
|
|
|
luaL_argerror(L,1,"this protocol is already registered as postdissector");
|
|
|
|
}
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-02-21 06:11:41 +00:00
|
|
|
if (all_fields) {
|
2017-04-12 02:53:48 +00:00
|
|
|
/*
|
|
|
|
* XXX - are there any Lua postdissectors that need "all fields",
|
|
|
|
* i.e. the entire protocol tree, or do they just look for
|
|
|
|
* *particular* fields, with field extractors?
|
|
|
|
*
|
|
|
|
* And do all of them require the actual *displayed* format of
|
|
|
|
* the fields they need?
|
|
|
|
*
|
|
|
|
* If not, this is overkill.
|
|
|
|
*/
|
2014-02-21 06:11:41 +00:00
|
|
|
epan_set_always_visible(TRUE);
|
|
|
|
}
|
|
|
|
|
2006-09-25 01:09:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-10 05:54:51 +00:00
|
|
|
WSLUA_METHOD Proto_register_heuristic(lua_State* L) {
|
2020-03-29 22:46:46 +00:00
|
|
|
/* Registers a heuristic dissector function for this <<lua_class_Proto,`Proto`>> protocol,
|
2014-03-23 15:01:12 +00:00
|
|
|
for the given heuristic list name.
|
|
|
|
|
|
|
|
When later called, the passed-in function will be given:
|
2020-03-29 22:46:46 +00:00
|
|
|
1. A <<lua_class_Tvb,`Tvb`>> object
|
|
|
|
2. A <<lua_class_Pinfo,`Pinfo`>> object
|
|
|
|
3. A <<lua_class_TreeItem,`TreeItem`>> object
|
2014-03-23 15:01:12 +00:00
|
|
|
|
|
|
|
The function must return `true` if the payload is for it, else `false`.
|
|
|
|
|
2014-03-10 05:54:51 +00:00
|
|
|
The function should perform as much verification as possible to ensure the payload is for it,
|
|
|
|
and dissect the packet (including setting TreeItem info and such) only if the payload is for it,
|
2014-03-23 15:01:12 +00:00
|
|
|
before returning true or false.
|
|
|
|
|
2014-12-30 01:49:05 +00:00
|
|
|
Since version 1.99.1, this function also accepts a Dissector object as the second argument,
|
|
|
|
to allow re-using the same Lua code as the `function proto.dissector(...)`. In this case,
|
|
|
|
the Dissector must return a Lua number of the number of bytes consumed/parsed: if 0 is returned,
|
|
|
|
it will be treated the same as a `false` return for the heuristic; if a positive or negative
|
|
|
|
number is returned, then the it will be treated the same as a `true` return for the heuristic,
|
|
|
|
meaning the packet is for this protocol and no other heuristic will be tried.
|
|
|
|
|
2014-03-23 15:01:12 +00:00
|
|
|
@since 1.11.3
|
|
|
|
*/
|
|
|
|
#define WSLUA_ARG_Proto_register_heuristic_LISTNAME 2 /* The heuristic list name this function
|
|
|
|
is a heuristic for (e.g., "udp" or
|
|
|
|
"infiniband.payload"). */
|
|
|
|
#define WSLUA_ARG_Proto_register_heuristic_FUNC 3 /* A Lua function that will be invoked for
|
|
|
|
heuristic dissection. */
|
2014-03-10 05:54:51 +00:00
|
|
|
Proto proto = checkProto(L,1);
|
|
|
|
const gchar *listname = luaL_checkstring(L, WSLUA_ARG_Proto_register_heuristic_LISTNAME);
|
|
|
|
const gchar *proto_name = proto->name;
|
2021-06-09 22:49:28 +00:00
|
|
|
const int top = lua_gettop(L);
|
2016-11-08 16:13:41 +00:00
|
|
|
gchar *short_name;
|
2014-03-10 05:54:51 +00:00
|
|
|
|
|
|
|
if (!proto_name || proto->hfid == -1) {
|
|
|
|
/* this shouldn't happen - internal bug if it does */
|
|
|
|
luaL_error(L,"Proto_register_heuristic: got NULL proto name or invalid hfid");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* verify listname has a heuristic list */
|
|
|
|
if (!has_heur_dissector_list(listname)) {
|
|
|
|
luaL_error(L, "there is no heuristic list for '%s'", listname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-08 16:13:41 +00:00
|
|
|
short_name = wmem_strconcat(NULL, proto->loname, "_", listname, NULL);
|
|
|
|
|
2016-03-12 11:46:47 +00:00
|
|
|
/* verify that this is not already registered */
|
2016-11-08 16:13:41 +00:00
|
|
|
if (find_heur_dissector_by_unique_short_name(short_name)) {
|
|
|
|
wmem_free(NULL, short_name);
|
2016-03-12 11:46:47 +00:00
|
|
|
luaL_error(L, "'%s' is already registered as heuristic", proto->loname);
|
2016-11-08 16:13:41 +00:00
|
|
|
return 0;
|
2016-03-12 11:46:47 +00:00
|
|
|
}
|
2016-11-08 16:13:41 +00:00
|
|
|
wmem_free(NULL, short_name);
|
2016-03-12 11:46:47 +00:00
|
|
|
|
2014-12-30 01:49:05 +00:00
|
|
|
/* we'll check if the second form of this function was called: when the second arg is
|
|
|
|
a Dissector obejct. The truth is we don't need the Dissector object to do this
|
|
|
|
form of registration, but someday we might... so we're using it as a boolean arg
|
|
|
|
right now and in the future might use it for other things in this registration.
|
|
|
|
*/
|
|
|
|
if (isDissector(L, WSLUA_ARG_Proto_register_heuristic_FUNC)) {
|
|
|
|
/* retrieve the Dissector's Lua function... first get the table of all dissector funcs */
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_dissectors_table_ref);
|
|
|
|
/* then get the one for this Proto */
|
|
|
|
lua_getfield(L, -1, proto_name);
|
|
|
|
|
|
|
|
if (!lua_isfunction(L,-1)) {
|
|
|
|
/* this shouldn't be possible */
|
|
|
|
luaL_error(L,"Proto_register_heuristic: could not get lua function from lua_dissectors_table");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* replace the Dissector with the function */
|
|
|
|
lua_replace(L, WSLUA_ARG_Proto_register_heuristic_FUNC);
|
|
|
|
/* pop the lua_dissectors_table */
|
|
|
|
lua_pop(L, 1);
|
2021-03-20 01:58:26 +00:00
|
|
|
ws_assert(top == lua_gettop(L));
|
2014-12-30 01:49:05 +00:00
|
|
|
}
|
|
|
|
|
2014-03-10 05:54:51 +00:00
|
|
|
/* heuristic functions are stored in a table in the registry; the registry has a
|
|
|
|
* table at reference lua_heur_dissectors_table_ref, and that table has keys for
|
|
|
|
* the heuristic listname (e.g., "udp", "tcp", etc.), and that key's value is a
|
|
|
|
* table of keys of the Proto->name, and their value is the function.
|
|
|
|
* So it's like registry[table_ref][heur_list_name][proto_name] = func
|
|
|
|
*/
|
|
|
|
if (lua_isfunction(L,WSLUA_ARG_Proto_register_heuristic_FUNC)) {
|
|
|
|
/* insert the heur dissector into the heur dissectors table */
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_heur_dissectors_table_ref);
|
|
|
|
/* the heuristic lists table is now at -1 */
|
|
|
|
if (!lua_istable(L,-1)) {
|
|
|
|
/* this shouldn't be possible */
|
|
|
|
luaL_error(L,"Proto_register_heuristic: could not get lua_heur_dissectors table from registry");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wslua_get_table(L,-1,listname)) {
|
|
|
|
/* no one's registered a lua heuristic for this list, so make a new list table */
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushvalue(L,-1); /* duplicate the table so we can set it as a field */
|
|
|
|
lua_setfield(L,-3,listname); /* sets this new list table into the lists table */
|
|
|
|
}
|
|
|
|
else if (wslua_get_field(L,-1,proto_name)) {
|
|
|
|
luaL_error(L,"A heuristic dissector for Proto '%s' is already registered for the '%s' list", proto_name, listname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the func, set it as the value for key proto_name in listname's table */
|
|
|
|
lua_pushvalue(L,WSLUA_ARG_Proto_register_heuristic_FUNC);
|
|
|
|
lua_setfield(L,-2,proto_name);
|
|
|
|
|
|
|
|
/* ok, we're done with lua stuff, pop what we added to the stack */
|
|
|
|
lua_pop(L,2); /* pop the lists table and the listname table */
|
2021-03-20 01:58:26 +00:00
|
|
|
ws_assert(top == lua_gettop(L));
|
2014-03-10 05:54:51 +00:00
|
|
|
|
2016-11-08 16:13:41 +00:00
|
|
|
short_name = wmem_strconcat(NULL, proto->loname, "_", listname, NULL);
|
|
|
|
|
2014-03-10 05:54:51 +00:00
|
|
|
/* now register the single/common heur_dissect_lua function */
|
2015-07-11 21:33:26 +00:00
|
|
|
/* XXX - ADD PARAMETERS FOR NEW heur_dissector_add PARAMETERS!!! */
|
2016-11-08 16:13:41 +00:00
|
|
|
heur_dissector_add(listname, heur_dissect_lua, proto_name, short_name, proto->hfid, HEURISTIC_ENABLE);
|
2014-03-10 05:54:51 +00:00
|
|
|
|
2016-11-08 16:13:41 +00:00
|
|
|
wmem_free(NULL, short_name);
|
2014-03-10 05:54:51 +00:00
|
|
|
} else {
|
|
|
|
luaL_argerror(L,3,"The heuristic dissector must be a function");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-19 08:22:55 +00:00
|
|
|
/* WSLUA_ATTRIBUTE Proto_dissector RW The protocol's dissector, a function you define.
|
2014-03-23 15:01:12 +00:00
|
|
|
|
|
|
|
When later called, the function will be given:
|
2020-03-29 22:46:46 +00:00
|
|
|
1. A <<lua_class_Tvb,`Tvb`>> object
|
|
|
|
2. A <<lua_class_Pinfo,`Pinfo`>> object
|
|
|
|
3. A <<lua_class_TreeItem,`TreeItem`>> object
|
2014-03-23 15:01:12 +00:00
|
|
|
*/
|
2010-10-21 12:41:15 +00:00
|
|
|
static int Proto_get_dissector(lua_State* L) {
|
2014-02-19 08:22:55 +00:00
|
|
|
Proto proto = checkProto(L,1);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2006-09-25 01:09:00 +00:00
|
|
|
if (proto->handle) {
|
|
|
|
pushDissector(L,proto->handle);
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
luaL_error(L,"The protocol hasn't been registered yet");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-21 12:41:15 +00:00
|
|
|
static int Proto_set_dissector(lua_State* L) {
|
2014-02-19 08:22:55 +00:00
|
|
|
Proto proto = checkProto(L,1);
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2014-02-19 08:22:55 +00:00
|
|
|
if (lua_isfunction(L,2)) {
|
2006-09-25 01:09:00 +00:00
|
|
|
/* insert the dissector into the dissectors table */
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_dissectors_table_ref);
|
|
|
|
lua_replace(L, 1);
|
|
|
|
lua_pushstring(L,proto->name);
|
2014-02-19 08:22:55 +00:00
|
|
|
lua_insert(L, 2); /* function is now at 3 */
|
2006-09-25 01:09:00 +00:00
|
|
|
lua_settable(L,1);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-11-04 11:04:20 +00:00
|
|
|
if (! proto->handle) {
|
2015-12-11 01:56:03 +00:00
|
|
|
proto->handle = register_dissector(proto->loname, dissect_lua, proto->hfid);
|
2014-11-04 11:04:20 +00:00
|
|
|
}
|
2006-09-25 01:09:00 +00:00
|
|
|
} else {
|
2014-02-19 08:22:55 +00:00
|
|
|
luaL_argerror(L,2,"The dissector of a protocol must be a function");
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
2014-02-19 08:22:55 +00:00
|
|
|
return 0;
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 15:01:12 +00:00
|
|
|
/* WSLUA_ATTRIBUTE Proto_prefs RO The preferences of this dissector. */
|
2010-10-21 12:41:15 +00:00
|
|
|
static int Proto_get_prefs(lua_State* L) {
|
2014-02-19 08:22:55 +00:00
|
|
|
Proto proto = checkProto(L,1);
|
2006-09-25 01:09:00 +00:00
|
|
|
pushPrefs(L,&proto->prefs);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-23 15:01:12 +00:00
|
|
|
/* WSLUA_ATTRIBUTE Proto_prefs_changed WO The preferences changed routine of this dissector,
|
|
|
|
a Lua function you define.
|
|
|
|
*/
|
2013-09-07 11:27:38 +00:00
|
|
|
static int Proto_set_prefs_changed(lua_State* L) {
|
2014-02-19 08:22:55 +00:00
|
|
|
Proto proto = checkProto(L,1);
|
2013-09-07 11:27:38 +00:00
|
|
|
|
2014-02-19 08:22:55 +00:00
|
|
|
if (lua_isfunction(L,2)) {
|
2013-09-07 11:27:38 +00:00
|
|
|
/* insert the prefs changed callback into the prefs_changed table */
|
|
|
|
lua_getglobal(L, WSLUA_PREFS_CHANGED);
|
|
|
|
lua_replace(L, 1);
|
|
|
|
lua_pushstring(L,proto->name);
|
2014-02-19 08:22:55 +00:00
|
|
|
lua_insert(L, 2); /* function is now at 3 */
|
2013-09-07 11:27:38 +00:00
|
|
|
lua_settable(L,1);
|
|
|
|
} else {
|
2014-02-19 08:22:55 +00:00
|
|
|
luaL_argerror(L,2,"The prefs of a protocol must be a function");
|
2013-09-07 11:27:38 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-19 08:22:55 +00:00
|
|
|
/* WSLUA_ATTRIBUTE Proto_init WO The init routine of this dissector, a function you define.
|
2014-03-23 15:01:12 +00:00
|
|
|
|
|
|
|
The called init function is passed no arguments.
|
|
|
|
*/
|
2010-10-21 12:41:15 +00:00
|
|
|
static int Proto_set_init(lua_State* L) {
|
2014-02-19 08:22:55 +00:00
|
|
|
Proto proto = checkProto(L,1);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-02-19 08:22:55 +00:00
|
|
|
if (lua_isfunction(L,2)) {
|
2013-09-06 22:22:27 +00:00
|
|
|
/* insert the init routine into the init_routines table */
|
|
|
|
lua_getglobal(L, WSLUA_INIT_ROUTINES);
|
2006-09-25 01:09:00 +00:00
|
|
|
lua_replace(L, 1);
|
|
|
|
lua_pushstring(L,proto->name);
|
2014-02-19 08:22:55 +00:00
|
|
|
lua_insert(L, 2); /* function is now at 3 */
|
2006-09-25 01:09:00 +00:00
|
|
|
lua_settable(L,1);
|
|
|
|
} else {
|
2014-02-19 08:22:55 +00:00
|
|
|
luaL_argerror(L,2,"The initializer of a protocol must be a function");
|
2010-05-12 08:08:01 +00:00
|
|
|
}
|
2014-02-19 08:22:55 +00:00
|
|
|
return 0;
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 15:01:12 +00:00
|
|
|
/* WSLUA_ATTRIBUTE Proto_name RO The name given to this dissector. */
|
2014-02-19 08:22:55 +00:00
|
|
|
WSLUA_ATTRIBUTE_STRING_GETTER(Proto,name);
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2014-03-23 15:01:12 +00:00
|
|
|
/* WSLUA_ATTRIBUTE Proto_description RO The description given to this dissector. */
|
2014-02-19 08:22:55 +00:00
|
|
|
WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(Proto,description,desc);
|
2011-08-25 18:52:54 +00:00
|
|
|
|
2014-03-23 15:01:12 +00:00
|
|
|
/* WSLUA_ATTRIBUTE Proto_fields RW The `ProtoField`s Lua table of this dissector. */
|
2010-10-21 12:41:15 +00:00
|
|
|
static int Proto_get_fields(lua_State* L) {
|
2014-02-19 08:22:55 +00:00
|
|
|
Proto proto = checkProto(L,1);
|
2006-09-25 01:09:00 +00:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-10-21 12:41:15 +00:00
|
|
|
static int Proto_set_fields(lua_State* L) {
|
2014-02-19 08:22:55 +00:00
|
|
|
Proto proto = checkProto(L,1);
|
2006-09-25 01:09:00 +00:00
|
|
|
#define FIELDS_TABLE 2
|
|
|
|
#define NEW_TABLE 3
|
|
|
|
#define NEW_FIELD 3
|
|
|
|
|
2009-06-08 19:59:31 +00:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields);
|
2014-02-19 08:22:55 +00:00
|
|
|
lua_insert(L,FIELDS_TABLE);
|
2009-06-08 19:59:31 +00:00
|
|
|
|
|
|
|
if( lua_istable(L,NEW_TABLE)) {
|
|
|
|
for (lua_pushnil(L); lua_next(L, NEW_TABLE); ) {
|
|
|
|
if (isProtoField(L,5)) {
|
|
|
|
luaL_ref(L,FIELDS_TABLE);
|
|
|
|
} else if (! lua_isnil(L,5) ) {
|
|
|
|
return luaL_error(L,"only ProtoFields should be in the table");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (isProtoField(L,NEW_FIELD)){
|
|
|
|
lua_pushvalue(L, NEW_FIELD);
|
|
|
|
luaL_ref(L,FIELDS_TABLE);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return luaL_error(L,"either a ProtoField or an array of protofields");
|
|
|
|
}
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2009-06-08 19:59:31 +00:00
|
|
|
lua_pushvalue(L, 3);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2006-09-25 01:09:00 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-25 22:11:05 +00:00
|
|
|
/* WSLUA_ATTRIBUTE Proto_experts RW The expert info Lua table of this `Proto`.
|
|
|
|
|
|
|
|
@since 1.11.3
|
|
|
|
*/
|
|
|
|
static int Proto_get_experts(lua_State* L) {
|
|
|
|
Proto proto = checkProto(L,1);
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, proto->expert_info_table_ref);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Proto_set_experts(lua_State* L) {
|
|
|
|
Proto proto = checkProto(L,1);
|
|
|
|
#define EI_TABLE 2
|
|
|
|
#define NEW_TABLE 3
|
|
|
|
#define NEW_FIELD 3
|
|
|
|
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, proto->expert_info_table_ref);
|
|
|
|
lua_insert(L,EI_TABLE);
|
|
|
|
|
|
|
|
if( lua_istable(L,NEW_TABLE)) {
|
|
|
|
for (lua_pushnil(L); lua_next(L, NEW_TABLE); ) {
|
|
|
|
if (isProtoExpert(L,5)) {
|
|
|
|
luaL_ref(L,EI_TABLE);
|
|
|
|
} else if (! lua_isnil(L,5) ) {
|
|
|
|
return luaL_error(L,"only ProtoExperts should be in the table");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (isProtoExpert(L,NEW_FIELD)){
|
|
|
|
lua_pushvalue(L, NEW_FIELD);
|
|
|
|
luaL_ref(L,EI_TABLE);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return luaL_error(L,"either a ProtoExpert or an array of ProtoExperts");
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pushvalue(L, 3);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-02-25 22:05:28 +00:00
|
|
|
/* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
|
2016-03-28 13:25:12 +00:00
|
|
|
static int Proto__gc(lua_State* L) {
|
2015-08-11 12:08:08 +00:00
|
|
|
/* Proto is registered twice, once in protocols_table_ref and once returned from Proto_new.
|
|
|
|
* It will not be freed unless deregistered.
|
|
|
|
*/
|
|
|
|
Proto proto = toProto(L,1);
|
|
|
|
|
|
|
|
if (!proto->expired) {
|
|
|
|
proto->expired = TRUE;
|
|
|
|
} else if (proto->hfid == -2) {
|
|
|
|
/* Only free deregistered Proto */
|
|
|
|
g_free(proto);
|
|
|
|
}
|
|
|
|
|
2013-02-25 22:05:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-19 08:22:55 +00:00
|
|
|
/* This table is ultimately registered as a sub-table of the class' metatable,
|
|
|
|
* and if __index/__newindex is invoked then it calls the appropriate function
|
|
|
|
* from this table for getting/setting the members.
|
|
|
|
*/
|
|
|
|
WSLUA_ATTRIBUTES Proto_attributes[] = {
|
|
|
|
WSLUA_ATTRIBUTE_RWREG(Proto,dissector),
|
|
|
|
WSLUA_ATTRIBUTE_RWREG(Proto,fields),
|
2014-03-25 22:11:05 +00:00
|
|
|
WSLUA_ATTRIBUTE_RWREG(Proto,experts),
|
2014-02-19 08:22:55 +00:00
|
|
|
WSLUA_ATTRIBUTE_ROREG(Proto,prefs),
|
|
|
|
WSLUA_ATTRIBUTE_WOREG(Proto,prefs_changed),
|
|
|
|
WSLUA_ATTRIBUTE_WOREG(Proto,init),
|
|
|
|
WSLUA_ATTRIBUTE_ROREG(Proto,name),
|
|
|
|
WSLUA_ATTRIBUTE_ROREG(Proto,description),
|
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
WSLUA_METHODS Proto_methods[] = {
|
|
|
|
WSLUA_CLASS_FNREG(Proto,new),
|
2014-03-10 05:54:51 +00:00
|
|
|
WSLUA_CLASS_FNREG(Proto,register_heuristic),
|
2008-04-25 18:59:20 +00:00
|
|
|
{ NULL, NULL }
|
2006-09-25 01:09:00 +00:00
|
|
|
};
|
|
|
|
|
2014-02-19 08:22:55 +00:00
|
|
|
WSLUA_META Proto_meta[] = {
|
|
|
|
WSLUA_CLASS_MTREG(Proto,tostring),
|
|
|
|
WSLUA_CLASS_MTREG(Proto,call),
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2014-02-19 08:22:55 +00:00
|
|
|
int Proto_register(lua_State* L) {
|
2019-01-06 14:03:01 +00:00
|
|
|
WSLUA_REGISTER_CLASS_WITH_ATTRS(Proto);
|
2009-06-08 19:59:31 +00:00
|
|
|
|
2015-07-07 15:30:44 +00:00
|
|
|
outstanding_FuncSavers = g_ptr_array_new();
|
|
|
|
|
2009-06-08 19:59:31 +00:00
|
|
|
lua_newtable(L);
|
|
|
|
protocols_table_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2014-01-31 07:25:42 +00:00
|
|
|
return 0;
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 17:41:06 +00:00
|
|
|
/**
|
|
|
|
* Query field abbr that is defined and bound to a Proto in lua.
|
2014-09-09 18:05:52 +00:00
|
|
|
* They are not registered until the end of the initialization.
|
2013-10-22 17:41:06 +00:00
|
|
|
*/
|
2015-07-08 19:20:50 +00:00
|
|
|
ProtoField wslua_is_field_available(lua_State* L, const char* field_abbr) {
|
2013-10-22 17:41:06 +00:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref);
|
|
|
|
lua_pushnil(L);
|
|
|
|
while (lua_next(L, -2)) {
|
|
|
|
Proto proto;
|
|
|
|
proto = checkProto(L, -1);
|
2014-02-19 08:22:55 +00:00
|
|
|
|
2013-10-22 17:41:06 +00:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields);
|
2014-02-19 08:22:55 +00:00
|
|
|
|
2013-10-22 17:41:06 +00:00
|
|
|
lua_pushnil(L);
|
|
|
|
while (lua_next(L, -2)) {
|
|
|
|
ProtoField f = checkProtoField(L, -1);
|
2015-07-08 19:20:50 +00:00
|
|
|
if (strcmp(field_abbr, f->abbrev) == 0) {
|
2013-10-22 17:41:06 +00:00
|
|
|
/* found! */
|
|
|
|
lua_pop(L, 6);
|
2015-07-08 19:20:50 +00:00
|
|
|
return f;
|
2013-10-22 17:41:06 +00:00
|
|
|
}
|
|
|
|
lua_pop(L, 1); /* table value */
|
|
|
|
}
|
|
|
|
lua_pop(L, 2); /* proto->fields and table value */
|
|
|
|
}
|
|
|
|
lua_pop(L, 1); /* protocols_table_ref */
|
2014-02-19 08:22:55 +00:00
|
|
|
|
2015-07-08 19:20:50 +00:00
|
|
|
return NULL;
|
2013-10-22 17:41:06 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 19:54:26 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-08-11 12:08:08 +00:00
|
|
|
int wslua_deregister_protocols(lua_State* L) {
|
|
|
|
/* for each registered Proto protocol do... */
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref);
|
|
|
|
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
|
|
|
Proto proto;
|
|
|
|
proto = checkProto(L, -1);
|
|
|
|
|
|
|
|
if (proto->handle) {
|
|
|
|
deregister_dissector(proto->loname);
|
|
|
|
}
|
|
|
|
if (proto->prefs_module) {
|
|
|
|
Pref pref;
|
|
|
|
prefs_deregister_protocol(proto->hfid);
|
2019-01-25 21:55:24 +00:00
|
|
|
/* Preferences are unregistered, now free its memory via Pref__gc */
|
2015-08-11 12:08:08 +00:00
|
|
|
for (pref = proto->prefs.next; pref; pref = pref->next) {
|
2019-01-25 21:55:24 +00:00
|
|
|
int pref_ref = pref->ref;
|
|
|
|
pref->ref = LUA_NOREF;
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, pref_ref);
|
2015-08-11 12:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (proto->expert_module) {
|
|
|
|
expert_deregister_protocol(proto->expert_module);
|
|
|
|
}
|
|
|
|
proto_deregister_protocol(proto->name);
|
|
|
|
|
|
|
|
/* for each registered ProtoField do... */
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields);
|
|
|
|
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
|
|
|
ProtoField f = checkProtoField(L, -1);
|
2019-01-26 14:06:15 +00:00
|
|
|
|
|
|
|
/* Memory ownership was previously transferred to epan in Proto_commit */
|
|
|
|
f->name = NULL;
|
|
|
|
f->abbrev = NULL;
|
2019-10-28 08:52:12 +00:00
|
|
|
f->vs = NULL;
|
2019-01-26 14:06:15 +00:00
|
|
|
f->blob = NULL;
|
|
|
|
|
2015-08-11 12:08:08 +00:00
|
|
|
f->hfid = -2; /* Deregister ProtoField, freed in ProtoField__gc */
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
/* for each registered ProtoExpert do... */
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, proto->expert_info_table_ref);
|
|
|
|
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
|
|
|
ProtoExpert pe = checkProtoExpert(L,-1);
|
2019-10-28 14:11:15 +00:00
|
|
|
|
|
|
|
/* Memory ownership was previously transferred to epan in Proto_commit */
|
|
|
|
pe->abbrev = NULL;
|
|
|
|
pe->text = NULL;
|
|
|
|
|
2015-08-11 12:08:08 +00:00
|
|
|
pe->ids.hf = -2; /* Deregister ProtoExpert, freed in ProtoExpert__gc */
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
if (proto->hfa->len) {
|
|
|
|
proto_add_deregistered_data(g_array_free(proto->hfa,FALSE));
|
|
|
|
} else {
|
|
|
|
g_array_free(proto->hfa,TRUE);
|
|
|
|
}
|
|
|
|
|
2019-01-29 12:01:27 +00:00
|
|
|
/* No need for deferred deletion of subtree indexes */
|
|
|
|
g_array_free(proto->etta,TRUE);
|
2015-08-11 12:08:08 +00:00
|
|
|
|
|
|
|
if (proto->eia->len) {
|
|
|
|
proto_add_deregistered_data(g_array_free(proto->eia,FALSE));
|
|
|
|
} else {
|
|
|
|
g_array_free(proto->eia,TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
proto->hfid = -2; /* Deregister Proto, freed in Proto__gc */
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pop(L, 1); /* protocols_table_ref */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-21 12:41:15 +00:00
|
|
|
int Proto_commit(lua_State* L) {
|
2009-06-08 19:59:31 +00:00
|
|
|
lua_settop(L,0);
|
2014-03-25 22:11:05 +00:00
|
|
|
/* the following gets the table of registered Proto protocols and puts it on the stack (index=1) */
|
2009-06-08 19:59:31 +00:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, protocols_table_ref);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-03-25 22:11:05 +00:00
|
|
|
/* for each registered Proto protocol do... */
|
2009-06-08 19:59:31 +00:00
|
|
|
for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 2)) {
|
2014-03-25 22:11:05 +00:00
|
|
|
/* lua_next() pop'ed the nil, pushed a table entry key at index=2, with value at index=3.
|
|
|
|
In our case, the key is the Proto's name, and the value is the Proto object.
|
|
|
|
At next iteration, the value (Proto object) and ProtoExperts table will be pop'ed due
|
|
|
|
to lua_pop(L, 2), and when lua_next() returns 0 (no more table entries), it will have
|
|
|
|
pop'ed the final key itself, leaving just the protocols_table_ref table on the stack.
|
|
|
|
*/
|
2015-08-11 12:08:08 +00:00
|
|
|
Proto proto = checkProto(L,3);
|
2015-07-13 02:02:17 +00:00
|
|
|
gint* ettp = NULL;
|
2015-08-11 12:08:08 +00:00
|
|
|
|
|
|
|
proto->hfa = g_array_new(TRUE,TRUE,sizeof(hf_register_info));
|
|
|
|
proto->etta = g_array_new(TRUE,TRUE,sizeof(gint*));
|
|
|
|
proto->eia = g_array_new(TRUE,TRUE,sizeof(ei_register_info));
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2015-07-13 02:02:17 +00:00
|
|
|
ettp = &(proto->ett);
|
2015-08-11 12:08:08 +00:00
|
|
|
g_array_append_val(proto->etta,ettp);
|
2015-07-13 02:02:17 +00:00
|
|
|
|
2014-03-25 22:11:05 +00:00
|
|
|
/* get the Lua table of ProtoFields, push it on the stack (index=3) */
|
2009-06-08 19:59:31 +00:00
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, proto->fields);
|
|
|
|
|
2014-03-25 22:11:05 +00:00
|
|
|
/* for each ProtoField in the Lua table do... */
|
2009-06-08 19:59:31 +00:00
|
|
|
for (lua_pushnil(L); lua_next(L, 4); lua_pop(L, 1)) {
|
|
|
|
ProtoField f = checkProtoField(L,6);
|
2014-02-27 21:59:08 +00:00
|
|
|
hf_register_info hfri = { NULL, { NULL, NULL, FT_NONE, 0, NULL, 0, NULL, HFILL } };
|
2015-07-13 02:02:17 +00:00
|
|
|
ettp = &(f->ett);
|
2009-06-08 19:59:31 +00:00
|
|
|
|
2014-02-27 04:42:15 +00:00
|
|
|
hfri.p_id = &(f->hfid);
|
|
|
|
hfri.hfinfo.name = f->name;
|
2015-07-08 19:20:50 +00:00
|
|
|
hfri.hfinfo.abbrev = f->abbrev;
|
2014-02-27 04:42:15 +00:00
|
|
|
hfri.hfinfo.type = f->type;
|
|
|
|
hfri.hfinfo.display = f->base;
|
|
|
|
hfri.hfinfo.strings = VALS(f->vs);
|
|
|
|
hfri.hfinfo.bitmask = f->mask;
|
|
|
|
hfri.hfinfo.blurb = f->blob;
|
|
|
|
|
2019-01-26 14:06:15 +00:00
|
|
|
// XXX this will leak resources.
|
2009-06-08 19:59:31 +00:00
|
|
|
if (f->hfid != -2) {
|
|
|
|
return luaL_error(L,"fields can be registered only once");
|
|
|
|
}
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2009-06-08 19:59:31 +00:00
|
|
|
f->hfid = -1;
|
2015-08-11 12:08:08 +00:00
|
|
|
g_array_append_val(proto->hfa,hfri);
|
|
|
|
g_array_append_val(proto->etta,ettp);
|
2009-06-08 19:59:31 +00:00
|
|
|
}
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-03-25 22:11:05 +00:00
|
|
|
/* register the proto fields */
|
2015-08-11 12:08:08 +00:00
|
|
|
proto_register_field_array(proto->hfid,(hf_register_info*)(void*)proto->hfa->data,proto->hfa->len);
|
|
|
|
proto_register_subtree_array((gint**)(void*)proto->etta->data,proto->etta->len);
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-03-25 22:11:05 +00:00
|
|
|
lua_pop(L,1); /* pop the table of ProtoFields */
|
|
|
|
|
|
|
|
/* now do the same thing for expert fields */
|
|
|
|
|
|
|
|
/* get the Lua table of ProtoExperts, push it on the stack (index=2) */
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, proto->expert_info_table_ref);
|
|
|
|
|
|
|
|
/* for each ProtoExpert in the Lua table do... */
|
|
|
|
for (lua_pushnil(L); lua_next(L, 4); lua_pop(L, 1)) {
|
|
|
|
ProtoExpert e = checkProtoExpert(L,6);
|
|
|
|
ei_register_info eiri = { NULL, { NULL, 0, 0, NULL, EXPFILL } };
|
|
|
|
|
|
|
|
eiri.ids = &(e->ids);
|
2015-07-08 19:20:50 +00:00
|
|
|
eiri.eiinfo.name = e->abbrev;
|
2014-03-25 22:11:05 +00:00
|
|
|
eiri.eiinfo.group = e->group;
|
|
|
|
eiri.eiinfo.severity = e->severity;
|
|
|
|
eiri.eiinfo.summary = e->text;
|
|
|
|
|
2019-10-28 14:11:15 +00:00
|
|
|
if (e->ids.ei != EI_INIT_EI || e->ids.hf != -2) {
|
2014-03-25 22:11:05 +00:00
|
|
|
return luaL_error(L,"expert fields can be registered only once");
|
|
|
|
}
|
|
|
|
|
2019-10-28 14:11:15 +00:00
|
|
|
e->ids.hf = -1;
|
2015-08-11 12:08:08 +00:00
|
|
|
g_array_append_val(proto->eia,eiri);
|
2014-03-25 22:11:05 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 12:08:08 +00:00
|
|
|
expert_register_field_array(proto->expert_module, (ei_register_info*)(void*)proto->eia->data, proto->eia->len);
|
2014-03-25 22:11:05 +00:00
|
|
|
|
|
|
|
/* Proto object and ProtoFields table will be pop'ed by lua_pop(L, 2) in for statement */
|
2009-06-08 19:59:31 +00:00
|
|
|
}
|
2010-05-12 08:08:01 +00:00
|
|
|
|
2014-01-31 07:25:42 +00:00
|
|
|
lua_pop(L,1); /* pop the protocols_table_ref */
|
|
|
|
|
2009-06-08 19:59:31 +00:00
|
|
|
return 0;
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2015-01-25 19:30:13 +00:00
|
|
|
static guint
|
|
|
|
wslua_dissect_tcp_get_pdu_len(packet_info *pinfo, tvbuff_t *tvb,
|
2016-03-28 13:25:12 +00:00
|
|
|
int offset, void *data)
|
2015-01-25 19:30:13 +00:00
|
|
|
{
|
2016-04-17 19:22:13 +00:00
|
|
|
/* WARNING: called from a TRY block, do not call luaL_error! */
|
2015-01-25 19:30:13 +00:00
|
|
|
func_saver_t* fs = (func_saver_t*)data;
|
|
|
|
lua_State* L = fs->state;
|
|
|
|
int pdu_len = 0;
|
|
|
|
|
|
|
|
lua_settop(L, 0);
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, fs->get_len_ref);
|
|
|
|
|
|
|
|
if (lua_isfunction(L,1)) {
|
|
|
|
|
|
|
|
push_Tvb(L,tvb);
|
|
|
|
push_Pinfo(L,pinfo);
|
|
|
|
lua_pushinteger(L,offset);
|
|
|
|
|
|
|
|
if ( lua_pcall(L,3,1,0) ) {
|
2016-04-17 19:22:13 +00:00
|
|
|
THROW_LUA_ERROR("Lua Error in dissect_tcp_pdus get_len_func: %s", lua_tostring(L,-1));
|
2015-01-25 19:30:13 +00:00
|
|
|
} else {
|
|
|
|
/* if the Lua dissector reported the consumed bytes, pass it to our caller */
|
|
|
|
if (lua_isnumber(L, -1)) {
|
|
|
|
/* we got the pdu_len */
|
|
|
|
pdu_len = wslua_togint(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
} else {
|
2016-04-17 19:22:13 +00:00
|
|
|
THROW_LUA_ERROR("Lua Error dissect_tcp_pdus: get_len_func did not return a Lua number of the PDU length");
|
2015-01-25 19:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2016-04-17 19:22:13 +00:00
|
|
|
REPORT_DISSECTOR_BUG("Lua Error in dissect_tcp_pdus: did not find the get_len_func dissector");
|
2015-01-25 19:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pdu_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
wslua_dissect_tcp_dissector(tvbuff_t *tvb, packet_info *pinfo,
|
|
|
|
proto_tree *tree, void *data)
|
|
|
|
{
|
wslua: fix crash when a LUA error is raised in TRY block
The dissect_tcp_pdus function in LUA is passed two LUA functions that
get the PDU length and the dissect a PDU. When one of these functions
fail, a longjmp is made to the the caller of lua_pcall.
This is no problem for the PDU length function, but the PDU dissect
function is wrapped in a TRY/CATCH/ENDTRY block which also uses longjmp
and need to be fully executed. Without doing so, LUA exceptions will
crash on a weird location (except_pop).
Fix the crash by not using luaL_error, but throw dissector errors which
properly breaks out of the tcp_dissect_pdus C function and then convert
it to a LUA error such that the dissector can handle it.
Test with `tshark -X lua_script:crash.lua -r ssl.pcap`:
trivial_proto = Proto("trivial", "Trivial Protocol")
function dissect_foo(tvb, pinfo, tree)
error("triggering a LUA error");
end
function get_pdu_len(tvb, pinfo, tree) return 5; end
function trivial_proto.dissector(tvb, pinfo, tree)
dissect_tcp_pdus(tvb, tree, 5, get_pdu_len, dissect_foo)
end
tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(443, trivial_proto)
It should not crash and will print this:
Lua Error: dissect_tcp_pdus dissect_func: [string "crash.lua"]:3: triggering a LUA error
Change-Id: Ibd079cc5eb3a2e4d2e62ea49a512fa2cc8e561ea
Reviewed-on: https://code.wireshark.org/review/10685
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Evan Huus <eapache@gmail.com>
2015-09-29 10:20:07 +00:00
|
|
|
/* WARNING: called from a TRY block, do not call luaL_error! */
|
2015-01-25 19:30:13 +00:00
|
|
|
func_saver_t* fs = (func_saver_t*)data;
|
|
|
|
lua_State* L = fs->state;
|
|
|
|
int consumed_bytes = 0;
|
|
|
|
|
|
|
|
lua_settop(L, 0);
|
|
|
|
lua_rawgeti(L, LUA_REGISTRYINDEX, fs->dissect_ref);
|
|
|
|
|
|
|
|
if (lua_isfunction(L,1)) {
|
|
|
|
|
|
|
|
push_Tvb(L,tvb);
|
|
|
|
push_Pinfo(L,pinfo);
|
2015-07-08 19:20:50 +00:00
|
|
|
/* XXX: not sure if it's kosher to just use the tree as the item */
|
|
|
|
push_TreeItem(L, tree, (proto_item*)tree);
|
2015-01-25 19:30:13 +00:00
|
|
|
|
|
|
|
if ( lua_pcall(L,3,1,0) ) {
|
wslua: fix crash when a LUA error is raised in TRY block
The dissect_tcp_pdus function in LUA is passed two LUA functions that
get the PDU length and the dissect a PDU. When one of these functions
fail, a longjmp is made to the the caller of lua_pcall.
This is no problem for the PDU length function, but the PDU dissect
function is wrapped in a TRY/CATCH/ENDTRY block which also uses longjmp
and need to be fully executed. Without doing so, LUA exceptions will
crash on a weird location (except_pop).
Fix the crash by not using luaL_error, but throw dissector errors which
properly breaks out of the tcp_dissect_pdus C function and then convert
it to a LUA error such that the dissector can handle it.
Test with `tshark -X lua_script:crash.lua -r ssl.pcap`:
trivial_proto = Proto("trivial", "Trivial Protocol")
function dissect_foo(tvb, pinfo, tree)
error("triggering a LUA error");
end
function get_pdu_len(tvb, pinfo, tree) return 5; end
function trivial_proto.dissector(tvb, pinfo, tree)
dissect_tcp_pdus(tvb, tree, 5, get_pdu_len, dissect_foo)
end
tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(443, trivial_proto)
It should not crash and will print this:
Lua Error: dissect_tcp_pdus dissect_func: [string "crash.lua"]:3: triggering a LUA error
Change-Id: Ibd079cc5eb3a2e4d2e62ea49a512fa2cc8e561ea
Reviewed-on: https://code.wireshark.org/review/10685
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Evan Huus <eapache@gmail.com>
2015-09-29 10:20:07 +00:00
|
|
|
THROW_LUA_ERROR("dissect_tcp_pdus dissect_func: %s", lua_tostring(L, -1));
|
2015-01-25 19:30:13 +00:00
|
|
|
} else {
|
|
|
|
/* if the Lua dissector reported the consumed bytes, pass it to our caller */
|
|
|
|
if (lua_isnumber(L, -1)) {
|
|
|
|
/* we got the consumed bytes or the missing bytes as a negative number */
|
|
|
|
consumed_bytes = wslua_togint(L, -1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
wslua: fix crash when a LUA error is raised in TRY block
The dissect_tcp_pdus function in LUA is passed two LUA functions that
get the PDU length and the dissect a PDU. When one of these functions
fail, a longjmp is made to the the caller of lua_pcall.
This is no problem for the PDU length function, but the PDU dissect
function is wrapped in a TRY/CATCH/ENDTRY block which also uses longjmp
and need to be fully executed. Without doing so, LUA exceptions will
crash on a weird location (except_pop).
Fix the crash by not using luaL_error, but throw dissector errors which
properly breaks out of the tcp_dissect_pdus C function and then convert
it to a LUA error such that the dissector can handle it.
Test with `tshark -X lua_script:crash.lua -r ssl.pcap`:
trivial_proto = Proto("trivial", "Trivial Protocol")
function dissect_foo(tvb, pinfo, tree)
error("triggering a LUA error");
end
function get_pdu_len(tvb, pinfo, tree) return 5; end
function trivial_proto.dissector(tvb, pinfo, tree)
dissect_tcp_pdus(tvb, tree, 5, get_pdu_len, dissect_foo)
end
tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(443, trivial_proto)
It should not crash and will print this:
Lua Error: dissect_tcp_pdus dissect_func: [string "crash.lua"]:3: triggering a LUA error
Change-Id: Ibd079cc5eb3a2e4d2e62ea49a512fa2cc8e561ea
Reviewed-on: https://code.wireshark.org/review/10685
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Evan Huus <eapache@gmail.com>
2015-09-29 10:20:07 +00:00
|
|
|
REPORT_DISSECTOR_BUG("dissect_tcp_pdus: did not find the dissect_func dissector");
|
2015-01-25 19:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return consumed_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WSLUA_FUNCTION wslua_dissect_tcp_pdus(lua_State* L) {
|
|
|
|
/* Make the TCP-layer invoke the given Lua dissection function for each
|
|
|
|
PDU in the TCP segment, of the length returned by the given get_len_func
|
|
|
|
function.
|
|
|
|
|
|
|
|
This function is useful for protocols that run over TCP and that are
|
|
|
|
either a fixed length always, or have a minimum size and have a length
|
|
|
|
field encoded within that minimum portion that identifies their full
|
|
|
|
length. For such protocols, their protocol dissector function can invoke
|
|
|
|
this `dissect_tcp_pdus()` function to make it easier to handle dissecting
|
|
|
|
their protocol's messages (i.e., their protocol data unit (PDU)). This
|
|
|
|
function shouild not be used for protocols whose PDU length cannot be
|
|
|
|
determined from a fixed minimum portion, such as HTTP or Telnet.
|
|
|
|
|
|
|
|
@since 1.99.2
|
|
|
|
*/
|
|
|
|
#define WSLUA_ARG_dissect_tcp_pdus_TVB 1 /* The Tvb buffer to dissect PDUs from. */
|
|
|
|
#define WSLUA_ARG_dissect_tcp_pdus_TREE 2 /* The Tvb buffer to dissect PDUs from. */
|
|
|
|
#define WSLUA_ARG_dissect_tcp_pdus_MIN_HEADER_SIZE 3 /* The number of bytes
|
|
|
|
in the fixed-length part of the PDU. */
|
|
|
|
#define WSLUA_ARG_dissect_tcp_pdus_GET_LEN_FUNC 4 /* A Lua function that will be
|
|
|
|
called for each PDU, to determine the full length of the
|
|
|
|
PDU. The called function will be given (1) the `Tvb` object
|
|
|
|
of the whole `Tvb` (possibly reassembled), (2) the `Pinfo` object,
|
|
|
|
and (3) an offset number of the index of the first byte
|
|
|
|
of the PDU (i.e., its first header byte). The Lua function
|
|
|
|
must return a Lua number of the full length of the PDU. */
|
|
|
|
#define WSLUA_ARG_dissect_tcp_pdus_DISSECT_FUNC 5 /* A Lua function that will be
|
|
|
|
called for each PDU, to dissect the PDU. The called
|
|
|
|
function will be given (1) the `Tvb` object of the PDU's
|
|
|
|
`Tvb` (possibly reassembled), (2) the `Pinfo` object,
|
|
|
|
and (3) the `TreeItem` object. The Lua function must
|
|
|
|
return a Lua number of the number of bytes read/handled,
|
|
|
|
which would typically be the `Tvb:len()`.*/
|
|
|
|
#define WSLUA_OPTARG_dissect_tcp_pdus_DESEGMENT 6 /* Whether to reassemble PDUs
|
|
|
|
crossing TCP segment boundaries or not. (default=true) */
|
|
|
|
Tvb tvb = checkTvb(L,WSLUA_ARG_dissect_tcp_pdus_TVB);
|
|
|
|
TreeItem ti = checkTreeItem(L,WSLUA_ARG_dissect_tcp_pdus_TREE);
|
|
|
|
guint fixed_len = (guint)luaL_checkinteger(L,WSLUA_ARG_dissect_tcp_pdus_MIN_HEADER_SIZE);
|
|
|
|
gboolean proto_desegment = wslua_optbool(L, WSLUA_OPTARG_dissect_tcp_pdus_DESEGMENT, TRUE);
|
|
|
|
|
|
|
|
if (!lua_pinfo) {
|
|
|
|
luaL_error(L,"dissect_tcp_pdus can only be invoked while in a dissect function");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lua_isfunction(L,WSLUA_ARG_dissect_tcp_pdus_GET_LEN_FUNC) &&
|
|
|
|
lua_isfunction(L,WSLUA_ARG_dissect_tcp_pdus_DISSECT_FUNC))
|
|
|
|
{
|
|
|
|
/* save the Lua functions so that we can call them later */
|
|
|
|
func_saver_t* fs = g_new(func_saver_t, 1);
|
|
|
|
|
|
|
|
lua_settop(L, WSLUA_ARG_dissect_tcp_pdus_DISSECT_FUNC);
|
|
|
|
|
|
|
|
fs->state = L;
|
|
|
|
/* the following pops the top function and sets a ref to it in the registry */
|
|
|
|
fs->dissect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
fs->get_len_ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
|
2015-07-07 15:30:44 +00:00
|
|
|
/* save the passed-in function refs, so Lua's garbage collector won't
|
|
|
|
destroy them before they get invoked */
|
2015-01-25 19:30:13 +00:00
|
|
|
g_ptr_array_add(outstanding_FuncSavers, fs);
|
|
|
|
|
wslua: fix crash when a LUA error is raised in TRY block
The dissect_tcp_pdus function in LUA is passed two LUA functions that
get the PDU length and the dissect a PDU. When one of these functions
fail, a longjmp is made to the the caller of lua_pcall.
This is no problem for the PDU length function, but the PDU dissect
function is wrapped in a TRY/CATCH/ENDTRY block which also uses longjmp
and need to be fully executed. Without doing so, LUA exceptions will
crash on a weird location (except_pop).
Fix the crash by not using luaL_error, but throw dissector errors which
properly breaks out of the tcp_dissect_pdus C function and then convert
it to a LUA error such that the dissector can handle it.
Test with `tshark -X lua_script:crash.lua -r ssl.pcap`:
trivial_proto = Proto("trivial", "Trivial Protocol")
function dissect_foo(tvb, pinfo, tree)
error("triggering a LUA error");
end
function get_pdu_len(tvb, pinfo, tree) return 5; end
function trivial_proto.dissector(tvb, pinfo, tree)
dissect_tcp_pdus(tvb, tree, 5, get_pdu_len, dissect_foo)
end
tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(443, trivial_proto)
It should not crash and will print this:
Lua Error: dissect_tcp_pdus dissect_func: [string "crash.lua"]:3: triggering a LUA error
Change-Id: Ibd079cc5eb3a2e4d2e62ea49a512fa2cc8e561ea
Reviewed-on: https://code.wireshark.org/review/10685
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Evan Huus <eapache@gmail.com>
2015-09-29 10:20:07 +00:00
|
|
|
WRAP_NON_LUA_EXCEPTIONS(
|
|
|
|
tcp_dissect_pdus(tvb->ws_tvb, lua_pinfo, ti->tree, proto_desegment,
|
|
|
|
fixed_len, wslua_dissect_tcp_get_pdu_len,
|
|
|
|
wslua_dissect_tcp_dissector, (void*)fs);
|
|
|
|
)
|
2015-01-25 19:30:13 +00:00
|
|
|
} else {
|
|
|
|
luaL_error(L,"The third and fourth arguments need to be Lua functions");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-10 16:07:04 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2014-09-10 16:07:04 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|