diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-11-18 13:43:33 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-11-18 13:43:33 +0000 |
commit | 6f0c375b601ba427261bec0d00c4d07f14b0d51b (patch) | |
tree | a00ff352d01520be1db108a5ecb067006c4ca03f /src/lua | |
parent | 95ed3b732549a6f5c5a7f39dd3e815eb18d0ffb7 (diff) | |
download | rspamd-6f0c375b601ba427261bec0d00c4d07f14b0d51b.tar.gz rspamd-6f0c375b601ba427261bec0d00c4d07f14b0d51b.zip |
Do not push ip from NULL string.
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_ip.c | 31 |
1 files 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 |