]> source.dussan.org Git - rspamd.git/commitdiff
Do not push ip from NULL string.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Nov 2013 13:43:33 +0000 (13:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Nov 2013 13:43:33 +0000 (13:43 +0000)
src/lua/lua_ip.c

index b0db30673a94c9a68ff959b09559caf286bd8672..89bb91ed005d8e14c1510695a2fffa0b36bba0b0 100644 (file)
@@ -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