summaryrefslogtreecommitdiffstats
path: root/src/lua/lua_map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/lua_map.c')
-rw-r--r--src/lua/lua_map.c19
1 files changed, 16 insertions, 3 deletions
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;