From ceeeea089ac68366d520eaf332fed4231ce8831e Mon Sep 17 00:00:00 2001 From: Hadriel Kaplan Date: Mon, 22 Dec 2014 19:14:49 -0500 Subject: [PATCH] Lua accessor for Protocol field type gets wrong data When a Lua dissector/tap accesses the value of a Field of FT_PROTOCOL ftype, the returned ByteArray contains the wrong data. Also, calling such a field's tostring() method returns a string of "(unknown)" instead of the hex of the data. Bug: 10801 Change-Id: I8a0642dc0e41af444d211bbe4106cd21207084a6 Reviewed-on: https://code.wireshark.org/review/6003 Petri-Dish: Alexis La Goutte Reviewed-by: Alexis La Goutte Tested-by: Petri Dish Buildbot Reviewed-by: Hadriel Kaplan Tested-by: Hadriel Kaplan --- epan/wslua/wslua_field.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/epan/wslua/wslua_field.c b/epan/wslua/wslua_field.c index 7d9e625a24..b07e98aa1a 100644 --- a/epan/wslua/wslua_field.c +++ b/epan/wslua/wslua_field.c @@ -174,7 +174,6 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) { /* FALLTHROUGH */ case FT_BYTES: case FT_UINT_BYTES: - case FT_PROTOCOL: case FT_REL_OID: case FT_SYSTEM_ID: case FT_OID: @@ -185,6 +184,16 @@ WSLUA_METAMETHOD FieldInfo__call(lua_State* L) { pushByteArray(L,ba); return 1; } + case FT_PROTOCOL: + { + ByteArray ba = g_byte_array_new(); + tvbuff_t* tvb = (tvbuff_t *) fvalue_get(&fi->ws_fi->value); + g_byte_array_append(ba, (const guint8 *)tvb_memdup(wmem_packet_scope(), tvb, 0, + tvb_captured_length(tvb)), tvb_captured_length(tvb)); + pushByteArray(L,ba); + return 1; + } + case FT_GUID: default: luaL_error(L,"FT_ not yet supported"); @@ -198,9 +207,19 @@ WSLUA_METAMETHOD FieldInfo__tostring(lua_State* L) { FieldInfo fi = checkFieldInfo(L,1); if (fi->ws_fi->value.ftype->val_to_string_repr) { - gchar* repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DISPLAY,NULL); + gchar* repr = NULL; + + if (fi->ws_fi->hfinfo->type == FT_PROTOCOL || fi->ws_fi->hfinfo->type == FT_PCRE) { + repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DFILTER,NULL); + } + else { + repr = fvalue_to_string_repr(&fi->ws_fi->value,FTREPR_DISPLAY,NULL); + } + if (repr) { lua_pushstring(L,repr); + /* fvalue_to_string_repr() g_malloc's the string's buffer */ + g_free(repr); } else { lua_pushstring(L,"(unknown)");