From: Vsevolod Stakhov Date: Mon, 18 Nov 2013 13:43:33 +0000 (+0000) Subject: Do not push ip from NULL string. X-Git-Tag: 0.6.0~53 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6f0c375b601ba427261bec0d00c4d07f14b0d51b;p=rspamd.git Do not push ip from NULL string. --- 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