diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2015-11-20 18:56:45 +0100 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2015-11-21 20:30:26 +0000 |
commit | 94b9907d0f32fe4d570d94b820b20b6906a21499 (patch) | |
tree | e92475a9ca019faeaad5525549671343ba5efb84 /epan/wslua | |
parent | 23258fb84145151680459756c64ade666e8a1773 (diff) |
Lua: Validate Proto() arguments
Check if description (protocol name) and short_name are used before
registering the protocol. This because proto_register_protocol() makes
sure there's not already a protocol with any of the names registered
and duplicates will be reported with a g_error() which terminates the
Wireshark unexpectedly.
Also check if short_name contains valid characters.
Give appropriate error messages.
Bug: 11739
Change-Id: Ib9776a2a3406ae5278ce744defd61864ebed0282
Reviewed-on: https://code.wireshark.org/review/11995
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'epan/wslua')
-rw-r--r-- | epan/wslua/wslua_proto.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index 4cfe734683..8721b451c7 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -93,7 +93,6 @@ WSLUA_CONSTRUCTOR Proto_new(lua_State* L) { const gchar* desc = luaL_checkstring(L,WSLUA_ARG_Proto_new_DESC); Proto proto; gchar *loname, *hiname; - int proto_id; /* TODO: should really make a common function for all of wslua that does checkstring and non-empty at same time */ if (!name[0]) { @@ -106,17 +105,29 @@ WSLUA_CONSTRUCTOR Proto_new(lua_State* L) { return 0; } + if (proto_name_already_registered(desc)) { + WSLUA_ARG_ERROR(Proto_new,DESC,"there cannot be two protocols with the same description"); + return 0; + } + loname = g_ascii_strdown(name, -1); - proto_id = proto_get_id_by_filter_name(loname); + if (proto_check_field_name(loname)) { + WSLUA_ARG_ERROR(Proto_new,NAME,"invalid character in name"); + g_free(loname); + return 0; + } - if (proto_id > 0) { + hiname = g_ascii_strup(name, -1); + if ((proto_get_id_by_short_name(hiname) != -1) || + (proto_get_id_by_filter_name(loname) != -1)) + { WSLUA_ARG_ERROR(Proto_new,NAME,"there cannot be two protocols with the same name"); g_free(loname); + g_free(hiname); return 0; } proto = (wslua_proto_t *)g_malloc(sizeof(wslua_proto_t)); - hiname = g_ascii_strup(name, -1); proto->name = hiname; proto->loname = loname; |