aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2006-01-25 02:08:10 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2006-01-25 02:08:10 +0000
commit0b9c8e52632d5498062df798b53157b0c8db5255 (patch)
treef8788324112fdee2922387d7afa23ccac77dcc5c /plugins
parenta91b4fb0c573e67db91c445b7f210d9b7a0315f2 (diff)
Avoid crashing when given an object of the wrong usertype
format_time() format_date() report_failure() svn path=/trunk/; revision=17097
Diffstat (limited to 'plugins')
-rw-r--r--plugins/lua/Makefile.am17
-rw-r--r--plugins/lua/packet-lua.c53
-rw-r--r--plugins/lua/packet-lua.h4
3 files changed, 54 insertions, 20 deletions
diff --git a/plugins/lua/Makefile.am b/plugins/lua/Makefile.am
index 81ee5d6aa4..65e050f3bd 100644
--- a/plugins/lua/Makefile.am
+++ b/plugins/lua/Makefile.am
@@ -68,20 +68,3 @@ TAR = tar
lua-5.0.2: lua-5.0.2.tar.gz
$(GUNZIP) lua-5.0.2.tar.gz | $(TAR) xf -
-lua_tvb.c : lua-5.0.2/lib/liblua.la
-
-lua_proto.c : lua-5.0.2/lib/liblua.la
-
-lua_tree.c : lua-5.0.2/lib/liblua.la
-
-lua_pinfo.c : lua-5.0.2/lib/liblua.la
-
-lua_tap.c : lua-5.0.2/lib/liblua.la
-
-packet-lua.c : lua-5.0.2/lib/liblua.la
-
-packet-lua.h : lua-5.0.2/lib/liblua.la
-
-
-lua-5.0.2/lib/liblua.la:
- cd lua-5.0.2 ; env -i PATH=$(PATH) make
diff --git a/plugins/lua/packet-lua.c b/plugins/lua/packet-lua.c
index 9555c4df37..69d45b58f6 100644
--- a/plugins/lua/packet-lua.c
+++ b/plugins/lua/packet-lua.c
@@ -27,11 +27,45 @@
*/
#include "packet-lua.h"
+#include <epan/nstime.h>
+#include <math.h>
+
static lua_State* L = NULL;
packet_info* lua_pinfo;
proto_tree* lua_tree;
dissector_handle_t lua_data_handle;
+static int lua_format_date(lua_State* L) {
+ lua_Number time = luaL_checknumber(L,1);
+ nstime_t then;
+ gchar* str;
+
+ then.secs = (guint32)floor(time);
+ then.nsecs = (guint32) ( (time-(double)(then.secs))*1000000000);
+ str = abs_time_to_str(&then);
+ lua_pushstring(L,str);
+
+ return 1;
+}
+
+static int lua_format_time(lua_State* L) {
+ lua_Number time = luaL_checknumber(L,1);
+ nstime_t then;
+ gchar* str;
+
+ then.secs = (guint32)floor(time);
+ then.nsecs = (guint32) ( (time-(double)(then.secs))*1000000000);
+ str = rel_time_to_str(&then);
+ lua_pushstring(L,str);
+
+ return 1;
+}
+
+static int lua_report_failure(lua_State* L) {
+ const gchar* s = luaL_checkstring(L,1);
+ report_failure("%s",s);
+ return 0;
+}
/* ethereal uses lua */
@@ -44,6 +78,7 @@ int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
lua_tree = edt->tree;
+ /* XXX in C */
lua_dostring(L,ep_strdup_printf("taps.%s(_ethereal_pinfo);",tap->name));
return 1;
@@ -51,11 +86,13 @@ int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
void lua_tap_reset(void *tapdata) {
Tap tap = tapdata;
+ /* XXX in C */
lua_dostring(L,ep_strdup_printf("tap_resets.%s();",tap->name));
}
void lua_tap_draw(void *tapdata) {
Tap tap = tapdata;
+ /* XXX in C */
lua_dostring(L,ep_strdup_printf("tap_draws.%s();",tap->name));
}
@@ -75,19 +112,21 @@ void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
lua_pinfo = pinfo;
+ /* XXX in C */
lua_dostring(L,ep_strdup_printf("dissectors.%s(_ethereal_tvb,_ethereal_pinfo,_ethereal_tree);",pinfo->current_proto));
lua_pinfo = NULL;
}
static void init_lua(void) {
+ /* XXX in C */
if (L)
lua_dostring(L, "for k in init_routines do init_routines[k]() end;");
}
void proto_reg_handoff_lua(void) {
lua_data_handle = find_dissector("data");
-
+ /* XXX in C */
if (L)
lua_dostring(L, "for k in handoff_routines do handoff_routines[k]() end ;");
}
@@ -144,6 +183,18 @@ void proto_register_lua(void)
Tap_register(L);
Address_register(L);
+ lua_pushstring(L, "format_date");
+ lua_pushcfunction(L, lua_format_date);
+ lua_settable(L, LUA_GLOBALSINDEX);
+
+ lua_pushstring(L, "format_time");
+ lua_pushcfunction(L, lua_format_time);
+ lua_settable(L, LUA_GLOBALSINDEX);
+
+ lua_pushstring(L, "report_failure");
+ lua_pushcfunction(L, lua_report_failure);
+ lua_settable(L, LUA_GLOBALSINDEX);
+
lua_pushstring(L, "handoff_routines");
lua_newtable (L);
lua_settable(L, LUA_GLOBALSINDEX);
diff --git a/plugins/lua/packet-lua.h b/plugins/lua/packet-lua.h
index c4b6e14a56..3a8618ccde 100644
--- a/plugins/lua/packet-lua.h
+++ b/plugins/lua/packet-lua.h
@@ -167,7 +167,7 @@ C check##C(lua_State* L, int index) { \
luaL_checktype(L,index,LUA_TUSERDATA); \
p = (C*)luaL_checkudata(L, index, CN); \
check_code; \
- return *p; \
+ return p ? *p : NULL; \
} \
C* push##C(lua_State* L, C v) { \
C* p = lua_newuserdata(L,sizeof(C)); *p = v; \
@@ -208,5 +208,5 @@ extern void dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree);
extern int lua_tap_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const void *data _U_);
extern void lua_tap_reset(void *tapdata);
extern void lua_tap_draw(void *tapdata);
-
+
#endif