From: Vsevolod Stakhov Date: Tue, 9 Feb 2016 16:43:40 +0000 (+0000) Subject: Fix some issues found by coverity X-Git-Tag: 1.2.0~271 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c2cbcd8d98ae8e1b8d1ef06bc6dc53f77ac3bd16;p=rspamd.git Fix some issues found by coverity --- diff --git a/src/libutil/addr.c b/src/libutil/addr.c index b70de6b9d..e95ac4c64 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -760,16 +760,16 @@ rspamd_inet_address_listen (const rspamd_inet_addr_t *addr, gint type, sa = &addr->u.in.addr.sa; } - setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof (gint)); + (void)setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof (gint)); #ifdef HAVE_IPV6_V6ONLY if (addr->af == AF_INET6) { /* We need to set this flag to avoid errors */ on = 1; #ifdef SOL_IPV6 - setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint)); + (void)setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint)); #elif defined(IPPROTO_IPV6) - setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint)); + (void)setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, sizeof (gint)); #endif } #endif diff --git a/src/libutil/http.c b/src/libutil/http.c index 605439129..21b763108 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -723,6 +723,7 @@ rspamd_http_decrypt_message (struct rspamd_http_connection *conn, msg->body_buf.len = 0; + memset (&decrypted_parser, 0, sizeof (decrypted_parser)); http_parser_init (&decrypted_parser, conn->type == RSPAMD_HTTP_SERVER ? HTTP_REQUEST : HTTP_RESPONSE); diff --git a/src/libutil/map.c b/src/libutil/map.c index 8d04fe236..ea5f3f210 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -802,7 +802,7 @@ rspamd_parse_abstract_list (rspamd_mempool_t * pool, c = p; data->state = 1; } - else if (*p == '\r' || *p == '\n') { + else if ((*p == '\r' || *p == '\n') && p > c) { /* Got EOL marker, save stored string */ s = strip_map_elt (pool, c, p - c); diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c index 7e80190e3..883d26580 100644 --- a/src/libutil/sqlite_utils.c +++ b/src/libutil/sqlite_utils.c @@ -337,6 +337,13 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const path, rc); #endif + if (has_lock && lock_fd != -1) { + msg_debug_pool_check ("removing lock from %s", lock_path); + rspamd_file_unlock (lock_fd, FALSE); + unlink (lock_path); + close (lock_fd); + } + return NULL; } @@ -418,7 +425,7 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const sqlite3_errmsg (sqlite)); } - if (has_lock) { + if (has_lock && lock_fd != -1) { msg_debug_pool_check ("removing lock from %s", lock_path); rspamd_file_unlock (lock_fd, FALSE); unlink (lock_path); diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index 6daf83993..89a6537de 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -1382,7 +1382,7 @@ gint rspamd_decode_hex_buf (const gchar *in, gsize inlen, guchar *out, gsize outlen) { - guchar *o, *end, ret; + guchar *o, *end, ret = 0; const gchar *p; gchar c; diff --git a/src/libutil/util.c b/src/libutil/util.c index 19ae980c0..e715c97cf 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -173,18 +173,25 @@ rspamd_inet_socket_create (gint type, struct addrinfo *addr, gboolean is_server, } if (is_server) { - setsockopt (fd, - SOL_SOCKET, - SO_REUSEADDR, - (const void *)&on, - sizeof (gint)); + if (setsockopt (fd, + SOL_SOCKET, + SO_REUSEADDR, + (const void *)&on, + sizeof (gint)) == -1) { + msg_warn ("setsockopt failed: %d, '%s'", errno, + strerror (errno)); + } #ifdef HAVE_IPV6_V6ONLY if (cur->ai_family == AF_INET6) { - setsockopt (fd, - IPPROTO_IPV6, - IPV6_V6ONLY, - (const void *)&on, - sizeof (gint)); + if (setsockopt (fd, + IPPROTO_IPV6, + IPV6_V6ONLY, + (const void *)&on, + sizeof (gint)) == -1) { + + msg_warn ("setsockopt failed: %d, '%s'", errno, + strerror (errno)); + } } #endif r = bind (fd, cur->ai_addr, cur->ai_addrlen); @@ -218,10 +225,12 @@ rspamd_inet_socket_create (gint type, struct addrinfo *addr, gboolean is_server, else { /* Still need to check SO_ERROR on socket */ optlen = sizeof (s_error); - getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen); - if (s_error) { - errno = s_error; - goto out; + + if (getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen) != -1) { + if (s_error) { + errno = s_error; + goto out; + } } } if (list == NULL) { @@ -314,8 +323,12 @@ rspamd_socket_unix (const gchar *path, goto out; } if (is_server) { - setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, - sizeof (gint)); + if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, + sizeof (gint)) == -1) { + msg_warn ("setsockopt failed: %d, '%s'", errno, + strerror (errno)); + } + r = bind (fd, (struct sockaddr *)addr, SUN_LEN (addr)); } else { @@ -348,10 +361,12 @@ rspamd_socket_unix (const gchar *path, else { /* Still need to check SO_ERROR on socket */ optlen = sizeof (s_error); - getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen); - if (s_error) { - errno = s_error; - goto out; + + if (getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&s_error, &optlen) != -1) { + if (s_error) { + errno = s_error; + goto out; + } } } @@ -496,6 +511,7 @@ rspamd_sockets_list (const gchar *credits, guint16 port, } if (fd != -1) { result = g_list_prepend (result, GINT_TO_POINTER (fd)); + fd = -1; } else { goto err; @@ -1747,12 +1763,20 @@ restart: /* Turn echo off */ if (tcgetattr (input, &oterm) != 0) { + close (input); errno = ENOTTY; return 0; } + memcpy (&term, &oterm, sizeof(term)); term.c_lflag &= ~(ECHO | ECHONL); - (void)tcsetattr (input, TCSAFLUSH, &term); + + if (tcsetattr (input, TCSAFLUSH, &term) == -1) { + errno = ENOTTY; + close (input); + return 0; + } + (void)write (output, "Enter passphrase: ", sizeof ("Enter passphrase: ") - 1); @@ -1816,7 +1840,7 @@ restart: } } - return p - buf; + return (p - buf); #endif } @@ -1942,7 +1966,7 @@ rspamd_init_libs (void) OTTERY_ENTROPY_SRC_RDRAND); } - ottery_init (ottery_cfg); + g_assert (ottery_init (ottery_cfg) == 0); #ifdef HAVE_LOCALE_H if (getenv ("LANG") == NULL) { diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index fa778ff6d..1ab7a746b 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -732,6 +732,7 @@ lua_config_register_pre_filter (lua_State *L) cd->callback.ref = luaL_ref (L, LUA_REGISTRYINDEX); cd->cb_is_ref = TRUE; } + cd->L = L; cfg->pre_filters = g_list_prepend (cfg->pre_filters, cd); rspamd_mempool_add_destructor (cfg->cfg_pool, @@ -753,6 +754,7 @@ lua_config_add_radix_map (lua_State *L) description = lua_tostring (L, 3); r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_compressed_t *)); *r = radix_create_compressed (); + if (!rspamd_map_add (cfg, map_line, description, rspamd_radix_read, rspamd_radix_fin, (void **)r)) { msg_warn_config ("invalid radix map %s", map_line); @@ -760,7 +762,8 @@ lua_config_add_radix_map (lua_State *L) lua_pushnil (L); return 1; } - ud = lua_newuserdata (L, sizeof (radix_compressed_t *)); + + ud = lua_newuserdata (L, sizeof (radix_compressed_t **)); *ud = r; rspamd_lua_setclass (L, "rspamd{radix}", -1); @@ -794,7 +797,7 @@ lua_config_radix_from_config (lua_State *L) r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_compressed_t *)); *r = radix_create_compressed (); radix_add_generic_iplist (ucl_obj_tostring (obj), r); - ud = lua_newuserdata (L, sizeof (radix_compressed_t *)); + ud = lua_newuserdata (L, sizeof (radix_compressed_t **)); *ud = r; rspamd_lua_setclass (L, "rspamd{radix}", -1); return 1; @@ -823,6 +826,7 @@ lua_config_add_hash_map (lua_State *L) description = lua_tostring (L, 3); r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *)); *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); + if (!rspamd_map_add (cfg, map_line, description, rspamd_hosts_read, rspamd_hosts_fin, (void **)r)) { msg_warn ("invalid hash map %s", map_line); @@ -830,10 +834,11 @@ lua_config_add_hash_map (lua_State *L) lua_pushnil (L); return 1; } + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_hash_table_destroy, *r); - ud = lua_newuserdata (L, sizeof (GHashTable *)); + ud = lua_newuserdata (L, sizeof (GHashTable **)); *ud = r; rspamd_lua_setclass (L, "rspamd{hash_table}", -1); @@ -857,6 +862,7 @@ lua_config_add_kv_map (lua_State *L) description = lua_tostring (L, 3); r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *)); *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); + if (!rspamd_map_add (cfg, map_line, description, rspamd_kv_list_read, rspamd_kv_list_fin, (void **)r)) { msg_warn_config ("invalid hash map %s", map_line); @@ -864,10 +870,11 @@ lua_config_add_kv_map (lua_State *L) lua_pushnil (L); return 1; } + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_hash_table_destroy, *r); - ud = lua_newuserdata (L, sizeof (GHashTable *)); + ud = lua_newuserdata (L, sizeof (GHashTable **)); *ud = r; rspamd_lua_setclass (L, "rspamd{hash_table}", -1); @@ -1062,7 +1069,12 @@ lua_config_register_symbols (lua_State *L) gdouble weight = 1.0; if (lua_gettop (L) < 3) { - msg_err_config ("not enough arguments to register a function"); + if (cfg) { + msg_err_config ("not enough arguments to register a function"); + } + + lua_error (L); + return 0; } if (cfg) { @@ -1231,6 +1243,11 @@ lua_config_register_dependency (lua_State * L) const gchar *name = NULL, *from = NULL; gint id; + if (cfg == NULL) { + lua_error (L); + return 0; + } + if (lua_type (L, 2) == LUA_TNUMBER) { id = luaL_checknumber (L, 2); name = luaL_checkstring (L, 3); diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 5f2dd2416..816565869 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -419,10 +419,6 @@ lua_http_request (lua_State *L) msg_err ("http request has bad params"); lua_pushboolean (L, FALSE); - if (mime_type) { - g_free (mime_type); - } - return 1; } @@ -434,6 +430,7 @@ lua_http_request (lua_State *L) cbd->mime_type = mime_type; msec_to_tv (timeout, &cbd->tv); cbd->fd = -1; + if (session) { cbd->session = session; rspamd_session_add_event (session, diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index 54126f22c..d82de9af9 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -358,7 +358,10 @@ lua_ip_from_string (lua_State *L) ip_str = luaL_checkstring (L, 1); if (ip_str) { ip = lua_ip_new (L, NULL); - rspamd_parse_inet_address (&ip->addr, ip_str, 0); + + if (!rspamd_parse_inet_address (&ip->addr, ip_str, 0)) { + msg_warn ("cannot parse ip: %s", ip_str); + } } else { lua_pushnil (L); @@ -525,11 +528,17 @@ rspamd_lua_ip_push_fromstring (lua_State *L, const gchar *ip_str) } else { ip = g_slice_alloc0 (sizeof (struct rspamd_lua_ip)); - rspamd_parse_inet_address (&ip->addr, ip_str, 0); - pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *)); - rspamd_lua_setclass (L, "rspamd{ip}", -1); - *pip = ip; + if (rspamd_parse_inet_address (&ip->addr, ip_str, 0)) { + + pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *)); + rspamd_lua_setclass (L, "rspamd{ip}", -1); + *pip = ip; + } + else { + g_slice_free1 (sizeof (*ip), ip); + lua_pushnil (L); + } } } diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c index a28db13d2..8f2f62c03 100644 --- a/src/lua/lua_logger.c +++ b/src/lua/lua_logger.c @@ -445,48 +445,57 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string) } else if (lua_type (L, 1) == LUA_TUSERDATA) { fmt_pos = 2; - lua_getmetatable (L, 1); - lua_pushstring (L, "__index"); - lua_gettable (L, -2); - lua_pushstring (L, "class"); - lua_gettable (L, -2); + if (lua_getmetatable (L, 1) != 0) { + lua_pushstring (L, "__index"); + lua_gettable (L, -2); - clsname = lua_tostring (L, -1); + lua_pushstring (L, "class"); + lua_gettable (L, -2); - if (strcmp (clsname, "rspamd{task}") == 0) { - struct rspamd_task *task = lua_check_task (L, 1); + clsname = lua_tostring (L, -1); - if (task) { - uid = task->task_pool->tag.uid; + if (strcmp (clsname, "rspamd{task}") == 0) { + struct rspamd_task *task = lua_check_task (L, 1); + + if (task) { + uid = task->task_pool->tag.uid; + } } - } - else if (strcmp (clsname, "rspamd{mempool}") == 0) { - rspamd_mempool_t *pool; + else if (strcmp (clsname, "rspamd{mempool}") == 0) { + rspamd_mempool_t *pool; - pool = rspamd_lua_check_mempool (L, 1); + pool = rspamd_lua_check_mempool (L, 1); - if (pool) { - uid = pool->tag.uid; + if (pool) { + uid = pool->tag.uid; + } } - } - else if (strcmp (clsname, "rspamd{config}") == 0) { - struct rspamd_config *cfg; + else if (strcmp (clsname, "rspamd{config}") == 0) { + struct rspamd_config *cfg; - cfg = lua_check_config (L, 1); + cfg = lua_check_config (L, 1); - if (cfg) { - uid = cfg->checksum; + if (cfg) { + uid = cfg->checksum; + } } + + /* Metatable, __index, classname */ + lua_pop (L, 3); } + else { + lua_error (L); - /* Metatable, __index, classname */ - lua_pop (L, 3); + return 0; + } } else { /* Bad argument type */ msg_err ("bad format string type: %s", lua_typename (L, lua_type (L, 1))); + lua_error (L); + return 0; } diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 4e02107f5..cc408244a 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -520,7 +520,6 @@ lua_redis_make_request (lua_State *L) ud->terminated = 0; ud->ctx = redisAsyncConnect (rspamd_inet_address_to_string (addr->addr), rspamd_inet_address_get_port (addr->addr)); - redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb); if (ud->ctx == NULL || ud->ctx->err) { if (ud->ctx) { @@ -534,6 +533,7 @@ lua_redis_make_request (lua_State *L) return 1; } + redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb); redisLibeventAttach (ud->ctx, ud->task->ev_base); ret = redisAsyncCommandArgv (ud->ctx, lua_redis_callback, @@ -757,7 +757,6 @@ lua_redis_connect (lua_State *L) ud->terminated = 0; ud->ctx = redisAsyncConnect (rspamd_inet_address_to_string (addr->addr), rspamd_inet_address_get_port (addr->addr)); - redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb); if (ud->ctx == NULL || ud->ctx->err) { REF_RELEASE (ctx); @@ -766,6 +765,7 @@ lua_redis_connect (lua_State *L) return 1; } + redisAsyncSetConnectCallback (ud->ctx, lua_redis_connect_cb); redisLibeventAttach (ud->ctx, ud->task->ev_base); pctx = lua_newuserdata (L, sizeof (ctx)); *pctx = ctx; diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index 615062bf2..9bd387a4b 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -610,6 +610,12 @@ lua_regexp_split (lua_State *L) } else if (lua_type (L, 2) == LUA_TUSERDATA) { t = lua_check_text (L, 2); + + if (t == NULL) { + lua_error (L); + return 0; + } + data = t->start; len = t->len; is_text = TRUE; diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 3f2b0723d..2eaeb221d 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -681,9 +681,14 @@ lua_task_get_cfg (lua_State *L) struct rspamd_task *task = lua_check_task (L, 1); struct rspamd_config **pcfg; - pcfg = lua_newuserdata (L, sizeof (gpointer)); - rspamd_lua_setclass (L, "rspamd{config}", -1); - *pcfg = task->cfg; + if (task) { + pcfg = lua_newuserdata (L, sizeof (gpointer)); + rspamd_lua_setclass (L, "rspamd{config}", -1); + *pcfg = task->cfg; + } + else { + lua_error (L); + } return 1; } @@ -694,8 +699,14 @@ lua_task_set_cfg (lua_State *L) struct rspamd_task *task = lua_check_task (L, 1); void *ud = luaL_checkudata (L, 2, "rspamd{config}"); - luaL_argcheck (L, ud != NULL, 1, "'config' expected"); - task->cfg = ud ? *((struct rspamd_config **)ud) : NULL; + if (task) { + luaL_argcheck (L, ud != NULL, 1, "'config' expected"); + task->cfg = ud ? *((struct rspamd_config **)ud) : NULL; + } + else { + lua_error (L); + } + return 0; } @@ -1020,7 +1031,7 @@ lua_task_set_request_header (lua_State *L) s = luaL_checklstring (L, 2, &len); - if (s) { + if (s && task) { if (lua_type (L, 3) == LUA_TSTRING) { v = luaL_checklstring (L, 2, &vlen); } @@ -2136,6 +2147,11 @@ lua_task_learn (lua_State *L) GError *err = NULL; int ret = 1; + if (task == NULL) { + lua_error (L); + return 0; + } + is_spam = lua_toboolean(L, 2); if (lua_gettop (L) > 2) { clname = luaL_checkstring (L, 3); @@ -2162,7 +2178,7 @@ lua_task_set_settings (lua_State *L) ucl_object_t *settings; settings = ucl_object_lua_import (L, 2); - if (settings != NULL) { + if (settings != NULL && task != NULL) { task->settings = settings; } @@ -2174,7 +2190,10 @@ lua_task_cache_get (lua_State *L) { struct rspamd_task *task = lua_check_task (L, 1); - msg_err_task ("this function is deprecated and will return nothing"); + if (task) { + msg_err_task ("this function is deprecated and will return nothing"); + } + lua_pushnumber (L, -1); return 1; @@ -2185,7 +2204,10 @@ lua_task_cache_set (lua_State *L) { struct rspamd_task *task = lua_check_task (L, 1); - msg_err_task ("this function is deprecated and will return nothing"); + if (task) { + msg_err_task ("this function is deprecated and will return nothing"); + } + lua_pushnumber (L, 0); return 1; diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c index 987818608..8f68d76d1 100644 --- a/src/lua/lua_trie.c +++ b/src/lua/lua_trie.c @@ -176,6 +176,7 @@ lua_trie_search_str (lua_State *L, ac_trie_t *trie, const gchar *str, gsize len, { struct lua_trie_cbdata cb; gboolean icase = FALSE; + gint ret; if (lua_gettop (L) == 4) { icase = lua_toboolean (L, 4); @@ -183,10 +184,13 @@ lua_trie_search_str (lua_State *L, ac_trie_t *trie, const gchar *str, gsize len, cb.L = L; cb.found = FALSE; - acism_lookup (trie, str, len, - lua_trie_callback, &cb, statep, icase); - return cb.found; + if ((ret = acism_lookup (trie, str, len, + lua_trie_callback, &cb, statep, icase)) == 0) { + return cb.found; + } + + return ret; } /*** diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c index d168597d3..be745206f 100644 --- a/src/lua/lua_upstream.c +++ b/src/lua/lua_upstream.c @@ -176,7 +176,7 @@ lua_upstream_list_create (lua_State *L) guint default_port = 0; def = luaL_checkstring (L, 2); - if (def) { + if (def && cfg) { if (lua_gettop (L) >= 3) { default_port = luaL_checknumber (L, 3); } @@ -193,6 +193,9 @@ lua_upstream_list_create (lua_State *L) lua_pushnil (L); } } + else { + lua_error (L); + } return 1; } diff --git a/src/lua_worker.c b/src/lua_worker.c index 60456b59f..6aba9e64f 100644 --- a/src/lua_worker.c +++ b/src/lua_worker.c @@ -290,6 +290,7 @@ lua_accept_socket (gint fd, short what, void *arg) } rspamd_inet_address_destroy (addr); + close (nfd); } static gboolean diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index e2e18d4e6..5813d1acd 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -500,7 +500,7 @@ dkim_module_check (struct dkim_check_result *res) } } - if (all_done && res != NULL) { + if (all_done) { rspamd_session_watcher_pop (res->task->s, res->w); } } diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 3b2bc54be..9edf7fc9d 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -408,10 +408,14 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj, gint cb_id if ((value = ucl_object_find_key (obj, "servers")) != NULL) { rule->servers = rspamd_upstreams_create (cfg->ups_ctx); + rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool, (rspamd_mempool_destruct_t)rspamd_upstreams_destroy, rule->servers); - rspamd_upstreams_from_ucl (rule->servers, value, DEFAULT_PORT, NULL); + if (!rspamd_upstreams_from_ucl (rule->servers, value, DEFAULT_PORT, NULL)) { + msg_err_config ("cannot read servers definition"); + return -1; + } } if ((value = ucl_object_find_key (obj, "fuzzy_map")) != NULL) { it = NULL; @@ -1650,7 +1654,7 @@ fuzzy_controller_timer_callback (gint fd, short what, void *arg) if (*session->saved > 0 ) { (*session->saved)--; - if (*session->saved == 0 && session->task != NULL) { + if (*session->saved == 0) { rspamd_task_free (session->task); session->task = NULL; } @@ -2031,7 +2035,7 @@ fuzzy_process_handler (struct rspamd_http_connection_entry *conn_ent, saved, err); } - if (res) { + if (res > 0) { processed = TRUE; } else if (res == -1) { diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 55a9b97ce..ca565f343 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -546,10 +546,13 @@ surbl_module_config (struct rspamd_config *cfg) if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector_hosts_map")) != NULL) { - rspamd_map_add (cfg, ucl_obj_tostring ( - value), + if (!rspamd_map_add (cfg, ucl_obj_tostring (value), "SURBL redirectors list", read_redirectors_list, fin_redirectors_list, - (void **)&surbl_module_ctx->redirector_map_data); + (void **)&surbl_module_ctx->redirector_map_data)) { + + msg_warn_config ("bad redirectors map definition: %s", + ucl_obj_tostring (value)); + } } if ((value = diff --git a/src/rspamadm/signtool.c b/src/rspamadm/signtool.c index dfe8ac123..34a5d7aa2 100644 --- a/src/rspamadm/signtool.c +++ b/src/rspamadm/signtool.c @@ -132,7 +132,7 @@ rspamadm_sign_file (const gchar *fname, const guchar *sk) rspamd_cryptobox_signature_bytes (mode)); rspamd_cryptobox_sign (sig, NULL, map, st.st_size, sk, mode); - write (fd_sig, sig, rspamd_cryptobox_signature_bytes (mode)); + g_assert (write (fd_sig, sig, rspamd_cryptobox_signature_bytes (mode)) != -1); close (fd_sig); munmap (map, st.st_size);