diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index f7bdf09c2d..682dc53061 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -118,7 +118,7 @@ typedef struct _wslua_field_t { enum ftenum type; unsigned base; const void* vs; - guint32 mask; + guint64 mask; } wslua_field_t; typedef struct _wslua_expert_field_t { @@ -771,6 +771,7 @@ extern void Int64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittle extern int Int64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian); extern void UInt64_pack(lua_State* L, luaL_Buffer *b, gint idx, gboolean asLittleEndian); extern int UInt64_unpack(lua_State* L, const gchar *buff, gboolean asLittleEndian); +extern guint64 getUInt64(lua_State *L, int i); extern Tvb* push_Tvb(lua_State* L, tvbuff_t* tvb); extern int push_wsluaTvb(lua_State* L, Tvb t); diff --git a/epan/wslua/wslua_int64.c b/epan/wslua/wslua_int64.c index 08a9100d11..e540d6d203 100644 --- a/epan/wslua/wslua_int64.c +++ b/epan/wslua/wslua_int64.c @@ -647,7 +647,7 @@ WSLUA_CLASS_DEFINE_BASE(UInt64,NOP,0); */ /* A checkUInt64 but that also auto-converts numbers, strings, and <> to a guint64. */ -static guint64 getUInt64(lua_State *L, int i) +guint64 getUInt64(lua_State *L, int i) { gchar *end = NULL; (void) end; diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c index 494aa099fe..fa8206e0a0 100644 --- a/epan/wslua/wslua_proto_field.c +++ b/epan/wslua/wslua_proto_field.c @@ -415,6 +415,27 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) { return tfs; } +static guint64 get_mask(lua_State* L, int idx, guint64 default_value) { + guint64 mask = default_value; + + switch(lua_type(L, idx)) { + case LUA_TNUMBER: + mask = (guint64)wslua_optguint32(L, idx, default_value); + break; + case LUA_TSTRING: + case LUA_TUSERDATA: + mask = getUInt64(L,idx); + break; + case LUA_TNIL: + case LUA_TNONE: + break; + default: + luaL_argerror(L,idx,"MASK field must be a number, UInt64 or string"); + break; + } + return mask; +} + static unit_name_string* unit_name_string_from_table(lua_State* L, int idx) { unit_name_string* units; @@ -541,7 +562,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { true_false_string *tfs = NULL; unit_name_string *uns = NULL; unsigned base; - guint32 mask = wslua_optguint32(L, WSLUA_OPTARG_ProtoField_new_MASK, 0x0); + guint64 mask = get_mask(L,WSLUA_OPTARG_ProtoField_new_MASK, 0x0); const gchar *blob = luaL_optstring(L,WSLUA_OPTARG_ProtoField_new_DESCR,NULL); gboolean base_unit_string = FALSE; gboolean base_range_string = FALSE; @@ -808,7 +829,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { range_string* rs32 = NULL; val64_string* vs64 = NULL; unit_name_string* uns = NULL; - guint32 mask = wslua_optguint32(L,5,0); + guint64 mask = get_mask(L,5,0); const gchar* blob = luaL_optstring(L,6,NULL); gboolean base_unit_string = FALSE; gboolean base_range_string = FALSE; @@ -948,7 +969,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint8_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint8_BASE One of `base.DEC`, `base.HEX` or `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING` or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint8_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint8_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint8_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint8_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -957,7 +978,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint16_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint16_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING` or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint16_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint16_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint16_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint16_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -966,7 +987,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint24_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint24_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint24_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint24_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint24_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint24_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -975,7 +996,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint32_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint32_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint32_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint32_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint32_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint32_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -984,7 +1005,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_uint64_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_uint64_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_uint64_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_uint64_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_uint64_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_uint64_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -993,7 +1014,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int8_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int8_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int8_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int8_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int8_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int8_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -1002,7 +1023,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int16_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int16_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int16_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int16_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int16_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int16_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -1011,7 +1032,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int24_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int24_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int24_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int24_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int24_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int24_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -1020,7 +1041,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int32_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int32_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int32_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int32_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int32_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int32_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -1029,7 +1050,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_int64_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_int64_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */ /* WSLUA_OPTARG_ProtoField_int64_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */ -/* WSLUA_OPTARG_ProtoField_int64_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_int64_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_int64_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -1038,7 +1059,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_framenum_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_framenum_BASE Only `base.NONE` is supported for framenum. */ /* WSLUA_OPTARG_ProtoField_framenum_FRAMETYPE One of `frametype.NONE`, `frametype.REQUEST`, `frametype.RESPONSE`, `frametype.ACK` or `frametype.DUP_ACK`. */ -/* WSLUA_OPTARG_ProtoField_framenum_MASK Integer mask of this field, which must be 0 for framenum. */ +/* WSLUA_OPTARG_ProtoField_framenum_MASK Integer, String or UInt64 mask of this field, which must be 0 for framenum. */ /* WSLUA_OPTARG_ProtoField_framenum_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -1061,7 +1082,7 @@ static int ProtoField_boolean(lua_State* L, enum ftenum type) { const gchar* name = luaL_optstring(L,2,abbr); unsigned base = (unsigned)luaL_optinteger(L, 3, BASE_NONE); true_false_string* tfs = NULL; - guint32 mask = wslua_optguint32(L,5,0); + guint64 mask = get_mask(L,5,0); const gchar* blob = luaL_optstring(L,6,NULL); if (!name[0]) { @@ -1112,7 +1133,7 @@ static int ProtoField_boolean(lua_State* L, enum ftenum type) { /* WSLUA_OPTARG_ProtoField_bool_NAME Actual name of the field (the string that appears in the tree). */ /* WSLUA_OPTARG_ProtoField_bool_DISPLAY How wide the parent bitfield is (`base.NONE` is used for NULL-value). */ /* WSLUA_OPTARG_ProtoField_bool_VALUESTRING A table containing the text that corresponds to the values. */ -/* WSLUA_OPTARG_ProtoField_bool_MASK Integer mask of this field. */ +/* WSLUA_OPTARG_ProtoField_bool_MASK Integer, String or UInt64 mask of this field. */ /* WSLUA_OPTARG_ProtoField_bool_DESC Description of the field. */ /* _WSLUA_RETURNS_ A <> object to be added to a table set to the <> attribute. */ @@ -1434,7 +1455,7 @@ PROTOFIELD_OTHER(eui64,FT_EUI64) WSLUA_METAMETHOD ProtoField__tostring(lua_State* L) { /* Returns a string with info about a protofield (for debugging purposes). */ ProtoField f = checkProtoField(L,1); - gchar* s = ws_strdup_printf("ProtoField(%i): %s %s %s %s %p %.8x %s", + gchar* s = ws_strdup_printf("ProtoField(%i): %s %s %s %s %p %.16lx %s", f->hfid,f->name,f->abbrev, ftenum_to_string(f->type), base_to_string(f->base), diff --git a/test/lua/int64.lua b/test/lua/int64.lua index 8582485b31..bc405c099b 100644 --- a/test/lua/int64.lua +++ b/test/lua/int64.lua @@ -337,6 +337,11 @@ test("min3",z==Int64.min()) test("minmax",Int64.min()== - Int64.max() - 1) +--Because of g_ascii_strtoll() usage without errno check, "invalid" strings are converted to 0 +testing("invalid string values") +test("invalid",Int64.new("invalid")== Int64.new(0,0)) +test("invalid2",UInt64.new("invalid")== UInt64.new(0,0)) + testing("error conditions") local function divtest(f,s) diff --git a/test/lua/protofield.lua b/test/lua/protofield.lua index 2fcfafb2fd..a83538982b 100644 --- a/test/lua/protofield.lua +++ b/test/lua/protofield.lua @@ -30,7 +30,7 @@ local function setFailed(name) end -- expected number of runs -local taptests = { [OTHER]=38 } +local taptests = { [OTHER]=66 } local function getResults() print("\n-----------------------------\n") for k,v in pairs(taptests) do @@ -91,6 +91,92 @@ test("ProtoField-char-unit-string", not success) success = pcall(ProtoField.new, "char base RANGE_STRING", "test.char5", ftypes.CHAR, {{1, 2, "Value"}}, base.RANGE_STRING) test("ProtoField-char-range-string", success) +-- Field type: BOOLEAN/UINT64 with (64 bit) mask +success = pcall(ProtoField.new, "boolean", "test.boolean0", ftypes.BOOLEAN, nil, base.HEX, 0x1) +test("ProtoField-new-bool-mask-trivial", success) + +success = pcall(ProtoField.new, "boolean", "test.boolean1", ftypes.BOOLEAN, nil, base.HEX, "1") +test("ProtoField-new-bool-mask-string", success) + +success = pcall(ProtoField.new, "boolean", "test.boolean2", ftypes.BOOLEAN, nil, base.HEX, UInt64(0x00000001, 0x0)) +test("ProtoField-new-bool-mask-uint64", success) + +success = pcall(ProtoField.new, "boolean", "test.boolean3", ftypes.BOOLEAN, nil, base.NONE, "invalid") -- 0 +test("ProtoField-new-bool-mask-string-invalid", success) + +success = pcall(ProtoField.new, "boolean", "test.boolean4", ftypes.BOOLEAN, nil, base.HEX, "-1") -- 0xFFFFFFFFFFFFFFFF +test("ProtoField-new-bool-mask-negative", success) + +success = pcall(ProtoField.new, "boolean", "test.boolean5", ftypes.BOOLEAN, nil, base.NONE) +test("ProtoField-new-bool-mask-none", success) + +success = pcall(ProtoField.new, "boolean", "test.boolean6", ftypes.BOOLEAN, nil, base.NONE, nil) +test("ProtoField-new-bool-mask-nil", success) + +success = pcall(ProtoField.bool, "test.boolean10", nil, 64, nil, 0x1) +test("ProtoField-bool-mask-trivial", success) + +success = pcall(ProtoField.bool, "test.boolean11", nil, 64, nil, "1") +test("ProtoField-bool-mask-string", success) + +success = pcall(ProtoField.bool, "test.boolean12", nil, 64, nil, UInt64(0x00000001, 0x0)) +test("ProtoField-bool-mask-uint64", success) + +success = pcall(ProtoField.bool, "test.boolean13", nil, base.NONE, nil, "invalid") -- 0 +test("ProtoField-bool-mask-string-invalid", success) + +success = pcall(ProtoField.bool, "test.boolean14", nil, 64, nil, "-1") -- 0xFFFFFFFFFFFFFFFF +test("ProtoField-bool-mask-negative", success) + +success = pcall(ProtoField.bool, "test.boolean15", nil, base.NONE, nil) +test("ProtoField-bool-mask-none", success) + +success = pcall(ProtoField.bool, "test.boolean16", nil, base.NONE, nil, nil) +test("ProtoField-bool-mask-nil", success) + +success = pcall(ProtoField.new, "uint64", "test.uint64_0", ftypes.UINT64, nil, base.HEX, 0x1) +test("ProtoField-new-uint64-mask-trivial", success) + +success = pcall(ProtoField.new, "uint64", "test.uint64_1", ftypes.UINT64, nil, base.HEX, "1") +test("ProtoField-new-uint64-mask-string", success) + +success = pcall(ProtoField.new, "uint64", "test.uint64_2", ftypes.UINT64, nil, base.HEX, UInt64(0x00000001, 0x0)) +test("ProtoField-new-uint64-mask-uint64", success) + +success = pcall(ProtoField.new, "uint64", "test.uint64_3", ftypes.UINT64, nil, base.NONE, "invalid") -- 0 +test("ProtoField-new-uint64-mask-string-invalid", success) + +success = pcall(ProtoField.new, "uint64", "test.uint64_4", ftypes.UINT64, nil, base.HEX, "-1") -- 0xFFFFFFFFFFFFFFFF +test("ProtoField-new-uint64-mask-negative", success) + +success = pcall(ProtoField.new, "uint64", "test.uint64_5", ftypes.UINT64, nil, base.NONE) +test("ProtoField-new-uint64-mask-none", success) + +success = pcall(ProtoField.new, "uint64", "test.uint64_6", ftypes.UINT64, nil, base.NONE, nil) +test("ProtoField-new-uint64-mask-nil", success) + +success = pcall(ProtoField.uint64, "test.uint64_10", nil, base.HEX, nil, 0x1) +test("ProtoField-uint64-mask-trivial", success) + +success = pcall(ProtoField.uint64, "test.uint64_11", nil, base.HEX, nil, "1") +test("ProtoField-uint64-mask-string", success) + +success = pcall(ProtoField.uint64, "test.uint64_12", nil, base.HEX, nil, UInt64(0x00000001, 0x0)) +test("ProtoField-uint64-mask-uint64", success) + +success = pcall(ProtoField.uint64, "test.uint64_13", nil, base.DEC, nil, "invalid") -- 0 +test("ProtoField-uint64-mask-string-invalid", success) + +success = pcall(ProtoField.uint64, "test.uint64_14", nil, base.DEC, nil, "-1") -- 0xFFFFFFFFFFFFFFFF +test("ProtoField-uint64-mask-negative", success) + +success = pcall(ProtoField.uint64, "test.uint64_15", nil, base.DEC, nil) +test("ProtoField-uint64-mask-none", success) + +success = pcall(ProtoField.uint64, "test.uint64_16", nil, base.DEC, nil, nil) +test("ProtoField-uint64-mask-nil", success) + + -- Field name: empty, illegal, incompatible success = pcall(ProtoField.int8, nil, "empty field name 1") test("ProtoField-empty-field-name-1", not success)