diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-03-13 15:01:18 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-03-13 15:01:55 +0000 |
commit | f7aee39a9dc81ae437e1dcc651a7335a7ae071d3 (patch) | |
tree | 491a5422b5e32feabad05fca0cdb9ae196f731a5 /src | |
parent | 376b5cac00888b7d3203f2c3e5611b0d25044c6b (diff) | |
download | rspamd-f7aee39a9dc81ae437e1dcc651a7335a7ae071d3.tar.gz rspamd-f7aee39a9dc81ae437e1dcc651a7335a7ae071d3.zip |
[Fix] Fix various issues found by PVS Studio
https://www.viva64.com/
Diffstat (limited to 'src')
-rw-r--r-- | src/client/rspamc.c | 14 | ||||
-rw-r--r-- | src/fuzzy_storage.c | 2 | ||||
-rw-r--r-- | src/libmime/archives.c | 5 | ||||
-rw-r--r-- | src/libserver/dkim.c | 2 | ||||
-rw-r--r-- | src/libserver/milter.c | 6 | ||||
-rw-r--r-- | src/libserver/rspamd_symcache.c | 1 | ||||
-rw-r--r-- | src/libserver/task.c | 2 | ||||
-rw-r--r-- | src/libutil/http_connection.c | 19 | ||||
-rw-r--r-- | src/libutil/logger.c | 2 | ||||
-rw-r--r-- | src/libutil/map.c | 2 | ||||
-rw-r--r-- | src/libutil/mem_pool.c | 18 | ||||
-rw-r--r-- | src/libutil/multipattern.c | 1 | ||||
-rw-r--r-- | src/libutil/rrd.c | 13 | ||||
-rw-r--r-- | src/libutil/shingles.c | 4 | ||||
-rw-r--r-- | src/lua/lua_common.c | 4 | ||||
-rw-r--r-- | src/lua/lua_config.c | 6 | ||||
-rw-r--r-- | src/lua/lua_html.c | 3 | ||||
-rw-r--r-- | src/lua/lua_http.c | 4 | ||||
-rw-r--r-- | src/lua/lua_thread_pool.c | 2 | ||||
-rw-r--r-- | src/lua/lua_util.c | 4 | ||||
-rw-r--r-- | src/plugins/surbl.c | 3 |
21 files changed, 60 insertions, 57 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 0568692b4..927097e18 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -680,15 +680,15 @@ add_options (GQueue *opts) if (kv == NULL || kv[1] == NULL) { ADD_CLIENT_HEADER (opts, *hdr, ""); - - if (kv) { - g_strfreev (kv); - } } else { ADD_CLIENT_HEADER (opts, kv[0], kv[1]); } + if (kv) { + g_strfreev (kv); + } + hdr ++; } } @@ -1006,9 +1006,9 @@ rspamc_counters_sort (const ucl_object_t **o1, const ucl_object_t **o2) order2 = ucl_object_toint (elt2); } } - - g_strfreev (args); } + + g_strfreev (args); } return (inverse ? (order2 - order1) : (order1 - order2)); @@ -2008,7 +2008,7 @@ main (gint argc, gchar **argv, gchar **env) g_queue_free_full (kwattrs, g_free); /* Wait for children processes */ - cur = g_list_first (children); + cur = children ? g_list_first (children) : NULL; ret = 0; while (cur) { diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 7fdce82ae..2054633ad 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -599,6 +599,7 @@ rspamd_fuzzy_send_update_mirror (struct rspamd_fuzzy_storage_ctx *ctx, conn->mirror = m; if (conn->up == NULL) { + g_free (conn); msg_err ("cannot select upstream for %s", m->name); return; } @@ -608,6 +609,7 @@ rspamd_fuzzy_send_update_mirror (struct rspamd_fuzzy_storage_ctx *ctx, SOCK_STREAM, TRUE); if (conn->sock == -1) { + g_free (conn); msg_err ("cannot connect upstream for %s", m->name); rspamd_upstream_fail (conn->up, TRUE); return; diff --git a/src/libmime/archives.c b/src/libmime/archives.c index f546570a9..b84670761 100644 --- a/src/libmime/archives.c +++ b/src/libmime/archives.c @@ -1146,12 +1146,14 @@ rspamd_7zip_read_coders_info (struct rspamd_task *task, return NULL; } - folder_nstreams = g_alloca (sizeof (int) * num_folders); + folder_nstreams = g_malloc (sizeof (int) * num_folders); for (i = 0; i < num_folders && p != NULL && p < end; i++) { p = rspamd_7zip_read_folder (task, p, end, arch, &folder_nstreams[i], &num_digests); } + + g_free (folder_nstreams); } break; case kCodersUnPackSize: @@ -1499,6 +1501,7 @@ rspamd_7zip_read_files_info (struct rspamd_task *task, if (fend == NULL || fend - p == 0) { /* Crap instead of fname */ msg_debug_archive ("bad 7zip name; %s", G_STRLOC); + goto end; } res = rspamd_7zip_ucs2_to_utf8 (task, p, fend); diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c index 9692d1b93..8100f8ee3 100644 --- a/src/libserver/dkim.c +++ b/src/libserver/dkim.c @@ -2664,6 +2664,7 @@ rspamd_dkim_sign_key_load (const gchar *key, gsize len, if (stat (key, &st) != 0) { g_set_error (err, dkim_error_quark (), DKIM_SIGERROR_KEYFAIL, "cannot stat key file: '%s' %s", key, strerror (errno)); + g_free (nkey); return NULL; } @@ -2674,6 +2675,7 @@ rspamd_dkim_sign_key_load (const gchar *key, gsize len, if (map == NULL) { g_set_error (err, dkim_error_quark (), DKIM_SIGERROR_KEYFAIL, "cannot map key file: '%s' %s", key, strerror (errno)); + g_free (nkey); return NULL; } diff --git a/src/libserver/milter.c b/src/libserver/milter.c index 236a4bf75..fcdbcae6c 100644 --- a/src/libserver/milter.c +++ b/src/libserver/milter.c @@ -1301,7 +1301,7 @@ rspamd_milter_del_header (struct rspamd_milter_session *session, value.len = 0; return rspamd_milter_send_action (session, RSPAMD_MILTER_CHGHEADER, - idx, name, value); + idx, name, &value); } void @@ -1935,7 +1935,7 @@ rspamd_milter_send_task_results (struct rspamd_milter_session *session, } } - rspamd_milter_set_reply (session, rcode, xcode, reply); + rspamd_milter_set_reply (session, xcode, rcode, reply); } break; case METRIC_ACTION_SOFT_REJECT: @@ -1949,7 +1949,7 @@ rspamd_milter_send_task_results (struct rspamd_milter_session *session, sizeof (RSPAMD_MILTER_TEMPFAIL_MESSAGE) - 1); } - rspamd_milter_set_reply (session, rcode, xcode, reply); + rspamd_milter_set_reply (session, xcode, rcode, reply); break; case METRIC_ACTION_REWRITE_SUBJECT: diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c index 3cfb15408..64e451f7a 100644 --- a/src/libserver/rspamd_symcache.c +++ b/src/libserver/rspamd_symcache.c @@ -1580,7 +1580,6 @@ rspamd_symcache_make_checkpoint (struct rspamd_task *task, checkpoint->pass = RSPAMD_CACHE_PASS_INIT; task->checkpoint = checkpoint; - task->result = task->result; return checkpoint; } diff --git a/src/libserver/task.c b/src/libserver/task.c index 30bccb81b..c4e69c974 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -1231,7 +1231,7 @@ rspamd_task_write_ialist (struct rspamd_task *task, struct rspamd_email_address *addr; gint i, nchars = 0, cur_chars; - if (lim <= 0) { + if (addrs && lim <= 0) { lim = addrs->len; } diff --git a/src/libutil/http_connection.c b/src/libutil/http_connection.c index dc3bfa9c0..42b934d2a 100644 --- a/src/libutil/http_connection.c +++ b/src/libutil/http_connection.c @@ -722,10 +722,15 @@ rspamd_http_simple_client_helper (struct rspamd_http_connection *conn) priv = conn->priv; ssl = priv->ssl; priv->ssl = NULL; - request_method = priv->msg->method; - /* Preserve host for keepalive */ - prev_host = priv->msg->host; - priv->msg->host = NULL; + + /* Preserve data */ + if (priv->msg) { + request_method = priv->msg->method; + /* Preserve host for keepalive */ + prev_host = priv->msg->host; + priv->msg->host = NULL; + } + rspamd_http_connection_reset (conn); priv->ssl = ssl; @@ -1988,12 +1993,6 @@ rspamd_http_connection_write_message_common (struct rspamd_http_connection *conn "" "\r\n", ENCRYPTED_VERSION, bodylen); } - - preludelen = rspamd_snprintf (repbuf, sizeof (repbuf), "%s\r\n" - "Content-Length: %z\r\n" - "Content-Type: %s\r\n" - "\r\n", ENCRYPTED_VERSION, bodylen, - mime_type); } else { preludelen = rspamd_snprintf (repbuf, sizeof (repbuf), diff --git a/src/libutil/logger.c b/src/libutil/logger.c index 45e99f8ae..7eb00f3fa 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -925,7 +925,7 @@ file_log_function (const gchar *module, const gchar *id, gchar *m; gdouble now; - struct iovec iov[5]; + struct iovec iov[6]; gulong r = 0, mr = 0; guint64 cksum; size_t mlen, mremain; diff --git a/src/libutil/map.c b/src/libutil/map.c index d4687e433..0f7ff4f48 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -2685,7 +2685,7 @@ rspamd_map_add_from_ucl (struct rspamd_config *cfg, } } - if (map->backends->len == 0) { + if (!map->backends || map->backends->len == 0) { msg_err_config ("map has no urls to be loaded: no valid backends"); goto err; } diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index 2f39a116d..a519013d1 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -490,9 +490,9 @@ void * rspamd_mempool_alloc0 (rspamd_mempool_t * pool, gsize size) { void *pointer = rspamd_mempool_alloc (pool, size); - if (pointer) { - memset (pointer, 0, size); - } + + memset (pointer, 0, size); + return pointer; } @@ -500,9 +500,9 @@ void * rspamd_mempool_alloc0_tmp (rspamd_mempool_t * pool, gsize size) { void *pointer = rspamd_mempool_alloc_tmp (pool, size); - if (pointer) { - memset (pointer, 0, size); - } + + memset (pointer, 0, size); + return pointer; } @@ -510,9 +510,8 @@ void * rspamd_mempool_alloc0_shared (rspamd_mempool_t * pool, gsize size) { void *pointer = rspamd_mempool_alloc_shared (pool, size); - if (pointer) { - memset (pointer, 0, size); - } + + memset (pointer, 0, size); return pointer; } @@ -800,7 +799,6 @@ rspamd_mempool_stat (rspamd_mempool_stat_t * st) st->shared_chunks_allocated = mem_pool_stat->shared_chunks_allocated; st->bytes_allocated = mem_pool_stat->bytes_allocated; st->chunks_allocated = mem_pool_stat->chunks_allocated; - st->shared_chunks_allocated = mem_pool_stat->shared_chunks_allocated; st->chunks_freed = mem_pool_stat->chunks_freed; st->oversized_chunks = mem_pool_stat->oversized_chunks; } diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c index 268170512..5f5724a0c 100644 --- a/src/libutil/multipattern.c +++ b/src/libutil/multipattern.c @@ -209,7 +209,6 @@ rspamd_multipattern_pattern_filter (const gchar *pattern, gsize len, g_free (tmp); } else if (flags & RSPAMD_MULTIPATTERN_RE) { - ret = malloc (len + 1); ret = rspamd_str_regexp_escape (pattern, len, dst_len, gl_flags | RSPAMD_REGEXP_ESCAPE_RE); } diff --git a/src/libutil/rrd.c b/src/libutil/rrd.c index 95d78c7f5..d17e823e6 100644 --- a/src/libutil/rrd.c +++ b/src/libutil/rrd.c @@ -228,12 +228,6 @@ rspamd_rrd_check_file (const gchar *filename, gboolean need_data, GError **err) close (fd); return FALSE; } - if (memcmp (head.version, RRD_VERSION, sizeof (head.version)) != 0) { - g_set_error (err, - rrd_error_quark (), EINVAL, "rrd head error: invalid version"); - close (fd); - return FALSE; - } if (head.float_cookie != RRD_FLOAT_COOKIE) { g_set_error (err, rrd_error_quark (), EINVAL, "rrd head error: another architecture " @@ -409,16 +403,12 @@ rspamd_rrd_open_common (const gchar *filename, gboolean completed, GError **err) file = g_malloc0 (sizeof (struct rspamd_rrd_file)); - if (file == NULL) { - g_set_error (err, rrd_error_quark (), ENOMEM, "not enough memory"); - return NULL; - } - /* Open file */ fd = rspamd_rrd_open_exclusive (filename); if (fd == -1) { g_set_error (err, rrd_error_quark (), errno, "rrd open error: %s", strerror (errno)); + g_free (file); return FALSE; } @@ -426,6 +416,7 @@ rspamd_rrd_open_common (const gchar *filename, gboolean completed, GError **err) g_set_error (err, rrd_error_quark (), errno, "rrd stat error: %s", strerror (errno)); rspamd_file_unlock (fd, FALSE); + g_free (file); close (fd); return FALSE; } diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c index 70aa5fe78..4affb16c3 100644 --- a/src/libutil/shingles.c +++ b/src/libutil/shingles.c @@ -184,6 +184,10 @@ rspamd_shingles_from_text (GArray *input, g_free (hashes); + if (pool != NULL) { + g_free (res); + } + return NULL; } diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 737455a3c..cff684aad 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -1940,7 +1940,6 @@ rspamd_lua_execute_lua_subprocess (lua_State *L, msg_err ("call to subprocess failed: %v", tb); /* Indicate error */ wlen = (1ULL << 63) + tb->len; - g_string_free (tb, TRUE); r = write (cbdata->sp[1], &wlen, sizeof (wlen)); if (r == -1) { @@ -1951,6 +1950,7 @@ rspamd_lua_execute_lua_subprocess (lua_State *L, if (r == -1) { msg_err ("write failed: %s", strerror (errno)); } + g_string_free (tb, TRUE); lua_pop (L, 1); } @@ -2205,9 +2205,9 @@ lua_worker_spawn_process (lua_State *L) if (rspamd_socketpair (cbdata->sp, TRUE) == -1) { msg_err ("cannot spawn socketpair: %s", strerror (errno)); - g_free (cbdata); luaL_unref (L, LUA_REGISTRYINDEX, cbdata->func_cbref); luaL_unref (L, LUA_REGISTRYINDEX, cbdata->cb_cbref); + g_free (cbdata); return 0; } diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index e846fd4d7..91c648e6f 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -3900,13 +3900,19 @@ lua_config_init_subsystem (lua_State *L) cfg); } else { + g_strfreev (parts); + return luaL_error (L, "no event base specified"); } } else { + g_strfreev (parts); + return luaL_error (L, "invalid param: %s", parts[i]); } } + + g_strfreev (parts); } else { return luaL_error (L, "invalid arguments"); diff --git a/src/lua/lua_html.c b/src/lua/lua_html.c index 63839c286..1b5828564 100644 --- a/src/lua/lua_html.c +++ b/src/lua/lua_html.c @@ -249,9 +249,6 @@ lua_html_has_property (lua_State *L) else if (strcmp (propname, "unbalanced") == 0) { ret = hc->flags & RSPAMD_HTML_FLAG_UNBALANCED; } - else if (strcmp (propname, "unbalanced") == 0) { - ret = hc->flags & RSPAMD_HTML_FLAG_UNBALANCED; - } else if (strcmp (propname, "data_urls") == 0) { ret = hc->flags & RSPAMD_HTML_FLAG_HAS_DATA_URLS; } diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 72eec70ad..e518e6dab 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -752,6 +752,10 @@ lua_http_request (lua_State *L) rspamd_fstring_free (body); } + if (mime_type) { + g_free (mime_type); + } + return luaL_error (L, "invalid body argument: %s", lua_typename (L, lua_type (L, -1))); } diff --git a/src/lua/lua_thread_pool.c b/src/lua/lua_thread_pool.c index ec9bfbe6f..d10f64579 100644 --- a/src/lua/lua_thread_pool.c +++ b/src/lua/lua_thread_pool.c @@ -305,7 +305,7 @@ lua_resume_thread_internal_full (struct thread_entry *thread_entry, } else { tb = rspamd_lua_get_traceback_string (thread_entry->lua_state); - if (thread_entry->error_callback) { + if (tb && thread_entry->error_callback) { thread_entry->error_callback (thread_entry, ret, tb->str); } else if (thread_entry->task) { diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index d78e230e7..dad8c336b 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -1177,7 +1177,7 @@ lua_util_tokenize_text (lua_State *L) { LUA_TRACE_POINT; const gchar *in = NULL; - gsize len, pos, ex_len, i; + gsize len = 0, pos, ex_len, i; GList *exceptions = NULL, *cur; struct rspamd_lua_text *t; struct rspamd_process_exception *ex; @@ -2243,6 +2243,8 @@ lua_util_gzip_decompress (lua_State *L) return luaL_error (L, "invalid arguments"); } + sz = t->len; + memset (&strm, 0, sizeof (strm)); /* windowBits +16 to decode gzip, zlib 1.2.0.4+ */ rc = inflateInit2 (&strm, MAX_WBITS + 16); diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 316ca7f62..d2632cb81 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -1864,9 +1864,6 @@ surbl_test_tags (struct rspamd_task *task, struct redirector_param *param, tld.len = url->tldlen; ftld = rspamd_mempool_ftokdup (task->task_pool, &tld); - } - - if (tag) { /* We know results for this URL */ DL_FOREACH (tag, cur) { |