diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2019-10-15 12:33:13 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-10-16 07:41:11 +0000 |
commit | 03719942232965069a1fc67d262ab32ab9b7ca2a (patch) | |
tree | b672b96618416e452b23e283da9b1d419f87f0b7 /epan/wslua | |
parent | 3a9933c52fdbc6c941ded112eeadc71c786f8f64 (diff) |
wslua: Improve parameter check in ProtoField.new()
Improve paremeter check in ProtoField.new() when using ftypes.CHAR:
- Check valid base types and give an error when not supported instead of
terminate in a g_error() (base.DEC is not supported).
- Give an error if used with base.UNIT_STRING instead of silently remove
the flags.
- Support base.RANGE_STRING instead of removing the flag.
Support using base.NONE with a valuestring.
Add ftypes.CHAR to the list of supported types.
Change-Id: I0e3f9698074c807f5da0de23ccd1be7446271135
Reviewed-on: https://code.wireshark.org/review/34783
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/wslua')
-rw-r--r-- | epan/wslua/wslua_proto_field.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c index 7a463cadc0..c050cdefbc 100644 --- a/epan/wslua/wslua_proto_field.c +++ b/epan/wslua/wslua_proto_field.c @@ -28,6 +28,7 @@ WSLUA_CLASS_DEFINE(ProtoField,FAIL_ON_NULL("null ProtoField")); static const wslua_ft_types_t ftenums[] = { {"ftypes.NONE", FT_NONE}, {"ftypes.BOOLEAN", FT_BOOLEAN}, + {"ftypes.CHAR", FT_CHAR}, {"ftypes.UINT8", FT_UINT8}, {"ftypes.UINT16", FT_UINT16}, {"ftypes.UINT24", FT_UINT24}, @@ -510,7 +511,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { appears in the tree). */ #define WSLUA_ARG_ProtoField_new_ABBR 2 /* Filter name of the field (the string that is used in filters). */ -#define WSLUA_ARG_ProtoField_new_TYPE 3 /* Field Type: one of: `ftypes.BOOLEAN`, `ftypes.UINT8`, +#define WSLUA_ARG_ProtoField_new_TYPE 3 /* Field Type: one of: `ftypes.BOOLEAN`, `ftypes.CHAR`, `ftypes.UINT8`, `ftypes.UINT16`, `ftypes.UINT24`, `ftypes.UINT32`, `ftypes.UINT64`, `ftypes.INT8`, `ftypes.INT16`, `ftypes.INT24`, `ftypes.INT32`, `ftypes.INT64`, `ftypes.FLOAT`, `ftypes.DOUBLE` , `ftypes.ABSOLUTE_TIME`, `ftypes.RELATIVE_TIME`, `ftypes.STRING`, @@ -586,6 +587,14 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { } break; case FT_CHAR: + if (nargs < WSLUA_OPTARG_ProtoField_new_BASE || lua_isnil(L, WSLUA_OPTARG_ProtoField_new_BASE)) { + base = BASE_OCT; /* Default base for characters (BASE_HEX instead?) */ + } + if (base & BASE_UNIT_STRING) { + WSLUA_OPTARG_ERROR(ProtoField_new, BASE, "Character type can not use base.UNIT_STRING"); + return 0; + } + /* FALLTHRU */ case FT_UINT8: case FT_UINT16: case FT_UINT24: @@ -596,11 +605,11 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { case FT_INT24: case FT_INT32: case FT_INT64: - if (type != FT_CHAR && base & BASE_UNIT_STRING) { + if (base & BASE_UNIT_STRING) { base_unit_string = TRUE; base &= ~BASE_UNIT_STRING; } - if (type != FT_CHAR && base & BASE_RANGE_STRING) { + if (base & BASE_RANGE_STRING) { base_range_string = TRUE; base &= ~BASE_RANGE_STRING; } @@ -608,14 +617,15 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { WSLUA_OPTARG_ERROR(ProtoField_new, BASE, "Only one of base.UNIT_STRING and base.RANGE_STRING can be specified"); return 0; } - - if (base == BASE_NONE) { - if (type == FT_CHAR) - base = BASE_OCT; /* default base for characters (BASE_HEX instead?) */ - else - base = BASE_DEC; /* Default base for integer */ + if (type != FT_CHAR && base == BASE_NONE) { + base = BASE_DEC; /* Default base for integer */ } - if ((base != BASE_DEC) && + if (type == FT_CHAR) { + if (base != BASE_NONE && base != BASE_HEX && base != BASE_OCT) { + luaL_argerror(L, 3, "Base must be either base.NONE, base.HEX or base.OCT"); + return 0; + } + } else if ((base != BASE_DEC) && (type == FT_INT8 || type == FT_INT16 || type == FT_INT24 || type == FT_INT32 || type == FT_INT64)) { WSLUA_OPTARG_ERROR(ProtoField_new,BASE,"Base must be either base.DEC or base.UNIT_STRING"); @@ -636,6 +646,10 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { vs32 = value_string_from_table(L,WSLUA_OPTARG_ProtoField_new_VALUESTRING); } } + if (type == FT_CHAR && base == BASE_NONE && rs32 == NULL && vs32 == NULL) { + luaL_argerror(L, 3, "Base base.NONE must be used with a valuestring"); + return 0; + } break; case FT_BOOLEAN: if (mask == 0x0 && base != BASE_NONE) { |