]> source.dussan.org Git - rspamd.git/commitdiff
Fix more issues found by coverity
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 10 Feb 2016 23:07:13 +0000 (23:07 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 10 Feb 2016 23:07:13 +0000 (23:07 +0000)
src/libserver/events.c
src/libserver/html.c
src/libserver/spf.c
src/libserver/symbols_cache.c
src/libserver/url.c
src/libstat/backends/mmaped_file.c
src/libstat/backends/redis_backend.c

index eb22efda5ac585a291924ad747922f9efdcef01a..a8cb086cbf93847095636782897e52ca2c7d9b06 100644 (file)
@@ -127,7 +127,7 @@ rspamd_session_add_event (struct rspamd_async_session *session,
        struct rspamd_async_event *new;
 
        if (session == NULL) {
-               msg_info_session ("session is NULL");
+               msg_err ("session is NULL");
                return;
        }
 
@@ -161,7 +161,7 @@ rspamd_session_remove_event (struct rspamd_async_session *session,
        struct rspamd_async_event search_ev, *found_ev;
 
        if (session == NULL) {
-               msg_info_session ("session is NULL");
+               msg_err ("session is NULL");
                return;
        }
 
@@ -213,7 +213,7 @@ gboolean
 rspamd_session_destroy (struct rspamd_async_session *session)
 {
        if (session == NULL) {
-               msg_info_session ("session is NULL");
+               msg_err ("session is NULL");
                return FALSE;
        }
 
@@ -231,7 +231,7 @@ void
 rspamd_session_cleanup (struct rspamd_async_session *session)
 {
        if (session == NULL) {
-               msg_info_session ("session is NULL");
+               msg_err ("session is NULL");
                return;
        }
 
index e1181764d9f6d61b94292e59e43489ff3d7b5b9a..47f4d78bde917df63a7794060c4c65890ac61e50 100644 (file)
@@ -1070,9 +1070,8 @@ rspamd_html_parse_tag_content (rspamd_mempool_t *pool,
                                        tag->id = found->id;
                                        tag->flags = found->flags;
                                }
+                               state = spaces_after_name;
                        }
-
-                       state = spaces_after_name;
                }
                break;
 
index 0e9179eb97d47d908619ec40ed0c8dcd73e295c8..c856d36456820ab80db506405d8ad83b352d56b9 100644 (file)
@@ -760,8 +760,10 @@ parse_spf_domain_mask (struct spf_record *rec, struct spf_addr *addr,
                                        /* Empty domain, technically an error */
                                        state = parse_slash;
                                }
-                               c = p;
-                               state = parse_domain;
+                               else {
+                                       c = p;
+                                       state = parse_domain;
+                               }
                                break;
                        case parse_domain:
                                if (t == '/') {
index 77cc75c2d554beb007d260c67dd3809f5eb2287f..b5facfce8505d6e3e75ffe87bff82f24172c784b 100644 (file)
@@ -746,9 +746,10 @@ rspamd_symbols_cache_validate_cb (gpointer k, gpointer v, gpointer ud)
 
        /* Check whether this item is skipped */
        skipped = !ghost;
+       g_assert (cache->cfg != NULL);
+
        if ((item->type &
                        (SYMBOL_TYPE_NORMAL|SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_COMPOSITE|SYMBOL_TYPE_CLASSIFIER))
-                       && cache->cfg
                        && g_hash_table_lookup (cache->cfg->metrics_symbols, item->symbol) == NULL) {
                cur = g_list_first (cache->cfg->metrics_list);
                while (cur) {
@@ -849,7 +850,7 @@ rspamd_symbols_cache_validate (struct symbols_cache *cache,
        gboolean ignore_symbol = FALSE, ret = TRUE;
 
        if (cache == NULL) {
-               msg_err_cache ("empty cache is invalid");
+               msg_err ("empty cache is invalid");
                return FALSE;
        }
 
index a32afd682726ca527931a64c9b3ed8cde53194f4..b756b1ca4412868bb1aeea041f93a2e2053c9f9e 100644 (file)
@@ -1588,10 +1588,7 @@ rspamd_tld_trie_find_callback (int strnum, int textpos, void *context)
 
        if (*pos != '.' || textpos != (gint)cbdata->len) {
                /* Something weird has been found */
-               if (textpos == (gint)cbdata->len - 1) {
-                       pos = cbdata->begin + textpos;
-               }
-               else {
+               if (textpos != (gint)cbdata->len - 1) {
                        /* Search more */
                        return 0;
                }
index 594f07d8b5a30f4de1b27e2626a77d28ee48f28f..d5b466a9af6faaf813ce11ee5ed2de947353d19e 100644 (file)
@@ -346,12 +346,14 @@ rspamd_mmaped_file_check (rspamd_mempool_t *pool, rspamd_mmaped_file_t * file)
        }
 
        f = (struct stat_file *)file->map;
-       c = f->header.magic;
+       c = &f->header.magic[0];
        /* Check magic and version */
        if (*c++ != 'r' || *c++ != 's' || *c++ != 'd') {
                msg_info_pool ("file %s is invalid stat file", file->filename);
                return -1;
        }
+
+       c = &f->header.version[0];
        /* Now check version and convert old version to new one (that can be used for sync */
        if (*c == 1 && *(c + 1) == 0) {
                return -1;
@@ -414,6 +416,7 @@ rspamd_mmaped_file_reindex (rspamd_mempool_t *pool,
                lock_fd = open (lock, O_RDONLY, 00600);
                if (lock_fd != -1) {
                        if (!rspamd_file_lock (lock_fd, FALSE)) {
+                               close (lock_fd);
                                g_free (lock);
 
                                return rspamd_mmaped_file_open (pool, filename, size, stcf);
@@ -608,8 +611,19 @@ rspamd_mmaped_file_open (rspamd_mempool_t *pool,
        /* Try to lock pages in RAM */
 
        /* Acquire lock for this operation */
-       rspamd_file_lock (new_file->fd, FALSE);
+       if (!rspamd_file_lock (new_file->fd, FALSE)) {
+               close (new_file->fd);
+               munmap (new_file->map, st.st_size);
+               msg_info_pool ("cannot lock file %s, error %d, %s",
+                               filename,
+                               errno,
+                               strerror (errno));
+               g_slice_free1 (sizeof (*new_file), new_file);
+               return NULL;
+       }
+
        if (rspamd_mmaped_file_check (pool, new_file) == -1) {
+               close (new_file->fd);
                rspamd_file_unlock (new_file->fd, FALSE);
                munmap (new_file->map, st.st_size);
                g_slice_free1 (sizeof (*new_file), new_file);
index 8fde4bfb4988c291b7f90d4edda1bb1947e055e3..406b76ab5184494d8586c7ec520551e786278112 100644 (file)
@@ -111,22 +111,24 @@ rspamd_redis_expand_object (const gchar *pattern,
                mod_char
        } state = just_char;
        struct rspamd_statfile_config *stcf;
-       lua_State *L;
+       lua_State *L = NULL;
        struct rspamd_task **ptask;
        GString *tb;
        const gchar *rcpt = NULL;
        gint err_idx;
 
-
        g_assert (ctx != NULL);
        stcf = ctx->stcf;
-       L = task->cfg->lua_state;
+
+       if (task) {
+               L = task->cfg->lua_state;
+       }
 
        if (ctx->enable_users) {
                if (ctx->cbref_user == -1) {
                        rcpt = rspamd_task_get_principal_recipient (task);
                }
-               else {
+               else if (L) {
                        /* Execute lua function to get userdata */
                        lua_pushcfunction (L, &rspamd_lua_traceback);
                        err_idx = lua_gettop (L);
@@ -357,7 +359,7 @@ rspamd_redis_tokens_to_query (struct rspamd_task *task, GPtrArray *tokens,
                                "%s\r\n"
                                "$%d\r\n"
                                "%s\r\n",
-                               learn ? (tokens->len * 2 + 2) : (tokens->len + 2),
+                               (tokens->len + 2),
                                larg0, arg0,
                                larg1, arg1);
        }