From: Vsevolod Stakhov Date: Mon, 27 Feb 2017 12:16:23 +0000 (+0000) Subject: [Minor] Accept strign keys for radix maps X-Git-Tag: 1.5.0~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fd449b38e77db529a69dd44ccfd7e90dcbbd7717;p=rspamd.git [Minor] Accept strign keys for radix maps --- diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index c74bcf31b..c0ce00609 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -540,9 +540,18 @@ lua_map_get_key (lua_State * L) if (map->type == RSPAMD_LUA_MAP_RADIX) { radix = map->data.radix; - if (lua_type (L, 2) == LUA_TNUMBER) { - key_num = luaL_checknumber (L, 2); - key_num = htonl (key_num); + if (lua_type (L, 2) == LUA_TSTRING) { + const gchar *addr_str; + gsize len; + + addr_str = luaL_checklstring (L, 2, &len); + addr = g_alloca (sizeof (*addr)); + addr->addr = g_alloca (rspamd_inet_address_storage_size ()); + + if (!rspamd_parse_inet_address_ip (addr_str, len, addr->addr)) { + addr = NULL; + msg_err ("invalid ip address: %*s", (gint)len, addr_str); + } } else if (lua_type (L, 2) == LUA_TUSERDATA) { ud = rspamd_lua_check_udata (L, 2, "rspamd{ip}"); @@ -557,6 +566,10 @@ lua_map_get_key (lua_State * L) msg_err ("invalid userdata type provided, rspamd{ip} expected"); } } + else if (lua_type (L, 2) == LUA_TNUMBER) { + key_num = luaL_checknumber (L, 2); + key_num = htonl (key_num); + } if (radix) { guintptr p = 0;