diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-05 18:20:22 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-02-05 18:20:22 +0000 |
commit | 1e08514471896e3b3069cdc25f457036d257cc68 (patch) | |
tree | b591aa5d3eac5fec70d137d664ccc4b95db63cc4 /src/lua | |
parent | 9068c5040e2737ce70f0cc9498000efa30c14c74 (diff) | |
download | rspamd-1e08514471896e3b3069cdc25f457036d257cc68.tar.gz rspamd-1e08514471896e3b3069cdc25f457036d257cc68.zip |
Fix potential issues as found by coverity.
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_buffer.c | 2 | ||||
-rw-r--r-- | src/lua/lua_config.c | 37 | ||||
-rw-r--r-- | src/lua/lua_ip.c | 4 |
3 files changed, 22 insertions, 21 deletions
diff --git a/src/lua/lua_buffer.c b/src/lua/lua_buffer.c index 5d00db585..7a23a9579 100644 --- a/src/lua/lua_buffer.c +++ b/src/lua/lua_buffer.c @@ -240,7 +240,7 @@ static int lua_io_dispatcher_set_policy (lua_State *L) { struct rspamd_io_dispatcher_s *io_dispatcher = lua_check_io_dispatcher (L); - gint policy, limit = -1; + gint policy, limit = 0; if (io_dispatcher) { policy = lua_tonumber (L, 2); diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 8e166ac32..8ca525f0e 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -895,25 +895,27 @@ rspamd_register_symbol_fromlua (lua_State *L, { struct lua_callback_data *cd; - cd = rspamd_mempool_alloc0 (cfg->cfg_pool, - sizeof (struct lua_callback_data)); - cd->cb_is_ref = TRUE; - cd->callback.ref = ref; - cd->L = L; if (name) { + cd = rspamd_mempool_alloc0 (cfg->cfg_pool, + sizeof (struct lua_callback_data)); + cd->cb_is_ref = TRUE; + cd->callback.ref = ref; + cd->L = L; cd->symbol = rspamd_mempool_strdup (cfg->cfg_pool, name); + + register_symbol_common (&cfg->cache, + name, + weight, + priority, + lua_metric_symbol_callback, + cd, + type); + rspamd_mempool_add_destructor (cfg->cfg_pool, + (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, + cd); } - register_symbol_common (&cfg->cache, - name, - weight, - priority, - lua_metric_symbol_callback, - cd, - type); - rspamd_mempool_add_destructor (cfg->cfg_pool, - (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, - cd); + } static gint @@ -1097,7 +1099,7 @@ lua_config_newindex (lua_State *L) name = luaL_checkstring (L, 2); - if (name != NULL && lua_gettop (L) > 2) { + if (cfg != NULL && name != NULL && lua_gettop (L) > 2) { if (lua_type (L, 3) == LUA_TFUNCTION) { /* Normal symbol from just a function */ lua_pushvalue (L, 3); @@ -1391,8 +1393,7 @@ lua_trie_search_text (lua_State *L) gboolean found = FALSE; if (trie) { - text = luaL_checkstring (L, 2); - len = strlen (text); + text = luaL_checklstring (L, 2, &len); if (text) { lua_newtable (L); pos = text; diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index b541727b2..7dea2bfcc 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -501,7 +501,7 @@ lua_ip_apply_mask (lua_State *L) guint32 umsk, *p; mask = lua_tonumber (L, 2); - if (mask > 0 && ip->is_valid) { + if (mask > 0 && ip != NULL && ip->is_valid) { if (ip->addr.af == AF_INET && mask <= 32) { nip = lua_ip_new (L, ip); umsk = htonl (G_MAXUINT32 << (32 - mask)); @@ -536,7 +536,7 @@ lua_ip_equal (lua_State *L) *ip2 = lua_check_ip (L, 2); gboolean res = FALSE; - if (ip1->is_valid && ip2->is_valid) { + if (ip1 && ip2 && ip1->is_valid && ip2->is_valid) { if (ip1->addr.af == ip2->addr.af) { if (ip1->addr.af == AF_INET) { if (memcmp(&ip1->addr.addr.s4.sin_addr, |