summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-10 23:07:13 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-10 23:07:13 +0000
commitbe13d1b8e409ebd64de46e5ca1b6a5c886932e38 (patch)
tree5f9f4d6eddcc1d02b516235c2172dad7c908fe0f
parentccb5d1f7b205821fae2924dd1b2bda91add277d1 (diff)
downloadrspamd-be13d1b8e409ebd64de46e5ca1b6a5c886932e38.tar.gz
rspamd-be13d1b8e409ebd64de46e5ca1b6a5c886932e38.zip
Fix more issues found by coverity
-rw-r--r--src/libserver/events.c8
-rw-r--r--src/libserver/html.c3
-rw-r--r--src/libserver/spf.c6
-rw-r--r--src/libserver/symbols_cache.c5
-rw-r--r--src/libserver/url.c5
-rw-r--r--src/libstat/backends/mmaped_file.c18
-rw-r--r--src/libstat/backends/redis_backend.c12
7 files changed, 36 insertions, 21 deletions
diff --git a/src/libserver/events.c b/src/libserver/events.c
index eb22efda5..a8cb086cb 100644
--- a/src/libserver/events.c
+++ b/src/libserver/events.c
@@ -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;
}
diff --git a/src/libserver/html.c b/src/libserver/html.c
index e1181764d..47f4d78bd 100644
--- a/src/libserver/html.c
+++ b/src/libserver/html.c
@@ -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;
diff --git a/src/libserver/spf.c b/src/libserver/spf.c
index 0e9179eb9..c856d3645 100644
--- a/src/libserver/spf.c
+++ b/src/libserver/spf.c
@@ -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 == '/') {
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 77cc75c2d..b5facfce8 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -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;
}
diff --git a/src/libserver/url.c b/src/libserver/url.c
index a32afd682..b756b1ca4 100644
--- a/src/libserver/url.c
+++ b/src/libserver/url.c
@@ -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;
}
diff --git a/src/libstat/backends/mmaped_file.c b/src/libstat/backends/mmaped_file.c
index 594f07d8b..d5b466a9a 100644
--- a/src/libstat/backends/mmaped_file.c
+++ b/src/libstat/backends/mmaped_file.c
@@ -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);
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index 8fde4bfb4..406b76ab5 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -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);
}