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>
This commit is contained in:
parent
b72d86602c
commit
17953ceea3
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue