From 6f0c375b601ba427261bec0d00c4d07f14b0d51b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 18 Nov 2013 13:43:33 +0000 Subject: [PATCH] Do not push ip from NULL string. --- src/lua/lua_ip.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index b0db30673..89bb91ed0 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -229,22 +229,27 @@ lua_ip_push_fromstring (lua_State *L, const gchar *ip_str) { struct rspamd_lua_ip *ip, **pip; - ip = g_slice_alloc (sizeof (struct rspamd_lua_ip)); - if (inet_pton (AF_INET, ip_str, &ip->data.ip4) == 1) { - ip->af = AF_INET; - } - else if (inet_pton (AF_INET6, ip_str, &ip->data.ip6) == 1) { - ip->af = AF_INET6; - } - else { - g_slice_free1 (sizeof (struct rspamd_lua_ip), ip); + if (ip_str == NULL) { lua_pushnil (L); - return; } + else { + ip = g_slice_alloc (sizeof (struct rspamd_lua_ip)); + if (inet_pton (AF_INET, ip_str, &ip->data.ip4) == 1) { + ip->af = AF_INET; + } + else if (inet_pton (AF_INET6, ip_str, &ip->data.ip6) == 1) { + ip->af = AF_INET6; + } + else { + g_slice_free1 (sizeof (struct rspamd_lua_ip), ip); + lua_pushnil (L); + return; + } - pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *)); - lua_setclass (L, "rspamd{ip}", -1); - *pip = ip; + pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *)); + lua_setclass (L, "rspamd{ip}", -1); + *pip = ip; + } } gint -- 2.39.5