diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2014-02-05 01:23:25 -0500 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2014-02-05 07:40:01 +0000 |
commit | 2466a7c6f1ef4db54c903432795fead5e106308f (patch) | |
tree | ae60730f27c2f4da7f313bec4e6c8a51bf15f804 | |
parent | c391d740fd92440ea515433f00889ec2b0e25960 (diff) |
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>
-rw-r--r-- | epan/wslua/wslua_proto.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index 98d2262a53..3ed6176d64 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -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; |