Fix Bug 9725 'Lua: ProtoField.new() is buggy'

Using ProtoField.new() is dicey.  Many of the optional arguments don't properly check the lua stack - they call lua_isnil() for their index number, instead of lua_gettop() to see the stack size.  lua_isnil() may return false in such cases.

Change-Id: I83ca1e5fc34e71ec35899adbedabcee69571b9fe
Reviewed-on: https://code.wireshark.org/review/118
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Stig Bjørlykke <stig@bjorlykke.org>
This commit is contained in:
Hadriel Kaplan 2014-02-05 01:23:25 -05:00 committed by Stig Bjørlykke
parent c391d740fd
commit 2466a7c6f1
1 changed files with 3 additions and 2 deletions

View File

@ -678,6 +678,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
#define WSLUA_OPTARG_ProtoField_new_DESCR 7 /* The description of the field. */
ProtoField f;
int nargs = lua_gettop(L);
const gchar* name = luaL_checkstring(L,WSLUA_ARG_ProtoField_new_NAME);
const gchar* abbr = luaL_checkstring(L,WSLUA_ARG_ProtoField_new_ABBR);
enum ftenum type;
@ -738,7 +739,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
{
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"This type does not display as hexadecimal");
}
if (!lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) {
if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING && !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) {
if (type == FT_UINT64 || type == FT_INT64) {
vs64 = val64_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING);
} else {
@ -753,7 +754,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
if (mask != 0x0 && (base < 1 || base > 64)) {
WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be between 1 and 64 if bitmask is non-zero.");
}
if (!lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) {
if (nargs >= WSLUA_OPTARG_ProtoField_new_VALUESTRING && !lua_isnil(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING)) {
tfs = true_false_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING);
}
break;