diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2017-03-14 10:30:20 +0100 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2017-03-14 20:40:07 +0000 |
commit | 17953ceea338598a7217edfab72f22a623d62f9f (patch) | |
tree | 81f6a3339114e8bb1b7ed50c17a43b0c9b97c01c /epan | |
parent | b72d86602cae511f7b53ae24654b41e1b56e58dc (diff) |
Lua: Check for no table in ProtoField unit string
When using base.UNIT_STRING in a ProtoField the table must be given.
Change-Id: Ie4beb93b5597a97a99939ef2c60a1ee7ece328f2
Reviewed-on: https://code.wireshark.org/review/20542
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/wslua/wslua_proto_field.c | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c index 64c3b667b1..cba174d9d6 100644 --- a/epan/wslua/wslua_proto_field.c +++ b/epan/wslua/wslua_proto_field.c @@ -146,17 +146,18 @@ static unsigned string_to_base(const gchar* str) { } static value_string* value_string_from_table(lua_State* L, int idx) { - GArray* vs = g_array_new(TRUE,TRUE,sizeof(value_string)); + GArray* vs; value_string* vs32; - if(lua_isnil(L,idx)) { + if (lua_isnil(L,idx)) { return NULL; } else if (!lua_istable(L,idx)) { - g_array_free(vs,TRUE); luaL_argerror(L,idx,"must be a table"); return NULL; } + vs = g_array_new(TRUE,TRUE,sizeof(value_string)); + lua_pushnil(L); while (lua_next(L, idx) != 0) { @@ -200,17 +201,18 @@ static value_string* value_string_from_table(lua_State* L, int idx) { } static val64_string* val64_string_from_table(lua_State* L, int idx) { - GArray* vs = g_array_new(TRUE,TRUE,sizeof(val64_string)); + GArray* vs; val64_string* vs64; - if(lua_isnil(L,idx)) { + if (lua_isnil(L,idx)) { return NULL; } else if (!lua_istable(L,idx)) { - g_array_free(vs,TRUE); luaL_argerror(L,idx,"must be a table"); return NULL; } + vs = g_array_new(TRUE,TRUE,sizeof(val64_string)); + lua_pushnil(L); while (lua_next(L, idx) != 0) { @@ -506,9 +508,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { " base.DEC_HEX, base.HEX_DEC or base.UNIT_STRING"); return 0; } - if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING && - !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) - { + if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING) { if (unit_string) { uns = unit_name_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING); } else if (type == FT_UINT64 || type == FT_INT64) { @@ -567,11 +567,11 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { break; case FT_FLOAT: case FT_DOUBLE: - if ((base & BASE_UNIT_STRING) && - (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING) && - !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) - { + if (base & BASE_UNIT_STRING) { + unit_string = TRUE; base &= ~BASE_UNIT_STRING; + } + if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING) { uns = unit_name_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING); } /* FALLTHRU */ @@ -619,6 +619,11 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { break; } + if (unit_string && !uns) { + WSLUA_OPTARG_ERROR(ProtoField_new,VALUESTRING, "Base is base.UNIT_STRING but no table is given"); + return 0; + } + f = g_new(wslua_field_t,1); f->hfid = -2; @@ -667,12 +672,21 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { unit_name_string* uns = NULL; guint32 mask = wslua_optguint32(L,5,0); const gchar* blob = luaL_optstring(L,6,NULL); + gboolean unit_string = FALSE; if (!name[0]) { luaL_argerror(L, 2, "cannot be an empty string"); return 0; } + if (base & BASE_UNIT_STRING) { + unit_string = TRUE; + base &= ~BASE_UNIT_STRING; + if (base == BASE_NONE) { + base = BASE_DEC; + } + } + if (lua_gettop(L) > 3 && !lua_isnil(L, 4)) { if (type == FT_FRAMENUM) { framenum_type = (enum ft_framenum_type) luaL_checkinteger(L, 4); @@ -680,12 +694,8 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { luaL_argerror(L, 4, "Invalid frametype"); return 0; } - } else if (base & BASE_UNIT_STRING) { + } else if (unit_string) { uns = unit_name_string_from_table(L,4); - base &= ~BASE_UNIT_STRING; - if (base == BASE_NONE) { - base = BASE_DEC; - } } else if (type == FT_UINT64 || type == FT_INT64) { vs64 = val64_string_from_table(L,4); } else { @@ -708,6 +718,11 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { return 0; } + if (unit_string && !uns) { + luaL_argerror(L, 4, "Base is base.UNIT_STRING but no table is given"); + return 0; + } + f = g_new(wslua_field_t,1); f->hfid = -2; |