commit 7fee396: [Minor] Fix some more issues

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Sep 21 11:28:05 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-09-21 12:13:44 +0100
URL: https://github.com/rspamd/rspamd/commit/7fee396041bb1250086c76517c02d8471c93a40c

[Minor] Fix some more issues
Found by: coverity scan

---
 src/libserver/rspamd_control.c  |  4 +++-
 src/libserver/rspamd_symcache.c |  8 +++++---
 src/libserver/ssl_util.c        |  2 +-
 src/libutil/expression.c        |  4 +++-
 src/libutil/fstring.c           | 25 +++++++++++--------------
 src/lua/lua_tcp.c               |  4 ++++
 6 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 0021485c3..b16ddf68f 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -781,7 +781,9 @@ rspamd_control_ignore_io_handler (int fd, short what, void *ud)
 	struct rspamd_control_reply rep;
 
 	/* At this point we just ignore replies from the workers */
-	(void) !read (fd, &rep, sizeof (rep));
+	if (read (fd, &rep, sizeof (rep)) == -1) {
+		msg_debug("cannot read %d bytes: %s", sizeof(rep), strerror(errno));
+	}
 	rspamd_control_stop_pending (elt);
 }
 
diff --git a/src/libserver/rspamd_symcache.c b/src/libserver/rspamd_symcache.c
index 41aa784b6..d1fb68672 100644
--- a/src/libserver/rspamd_symcache.c
+++ b/src/libserver/rspamd_symcache.c
@@ -588,8 +588,10 @@ rspamd_symcache_process_dep (struct rspamd_symcache *cache,
 		vdit = rspamd_symcache_find_filter (cache, dep->sym, false);
 
 		if (!vdit) {
-			msg_err_cache ("cannot add dependency from %s on %s: no dependency symbol registered",
-					dep->sym, dit->symbol);
+			if (dit) {
+				msg_err_cache ("cannot add dependency from %s on %s: no dependency symbol registered",
+						dep->sym, dit->symbol);
+			}
 		}
 		else {
 			msg_debug_cache ("process virtual dependency %s(%d) on %s(%d)", it->symbol,
@@ -698,7 +700,7 @@ rspamd_symcache_post_init (struct rspamd_symcache *cache)
 		vit = rspamd_symcache_find_filter (cache, ddep->from, false);
 		it = rspamd_symcache_find_filter (cache, ddep->from, true);
 
-		if (it == NULL) {
+		if (it == NULL || vit == NULL) {
 			msg_err_cache ("cannot register delayed dependency between %s and %s: "
 					"%s is missing", ddep->from, ddep->to, ddep->from);
 		}
diff --git a/src/libserver/ssl_util.c b/src/libserver/ssl_util.c
index b9fb175e5..40214ed89 100644
--- a/src/libserver/ssl_util.c
+++ b/src/libserver/ssl_util.c
@@ -637,7 +637,7 @@ rspamd_ssl_connection_new (gpointer ssl_ctx, struct ev_loop *ev_base,
 	conn->verify_peer = verify_peer;
 
 	if (log_tag) {
-		rspamd_strlcpy (conn->log_tag, log_tag, sizeof (log_tag));
+		rspamd_strlcpy (conn->log_tag, log_tag, sizeof (conn->log_tag));
 	}
 	else {
 		rspamd_random_hex (conn->log_tag, sizeof (log_tag) - 1);
diff --git a/src/libutil/expression.c b/src/libutil/expression.c
index ad78c0fcd..ccbe66195 100644
--- a/src/libutil/expression.c
+++ b/src/libutil/expression.c
@@ -1183,7 +1183,9 @@ rspamd_parse_expression (const gchar *line, gsize len,
 	return TRUE;
 
 error_label:
-	msg_debug_expression ("fatal error: %e", *err);
+	if (err && *err) {
+		msg_debug_expression ("fatal expression parse error: %e", *err);
+	}
 
 	while ((tmp = rspamd_expr_stack_elt_pop (operand_stack)) != NULL) {
 		g_node_destroy (tmp);
diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c
index 652d72d14..3f3af5357 100644
--- a/src/libutil/fstring.c
+++ b/src/libutil/fstring.c
@@ -272,25 +272,22 @@ rspamd_fstrhash_lc (const rspamd_ftok_t * str, gboolean is_utf)
 
 	p = str->begin;
 	hval = str->len;
+	end = p + str->len;
 
 	if (is_utf) {
-		while (end < str->begin + str->len) {
-			if (rspamd_fast_utf8_validate (p, str->len) != 0) {
-				return rspamd_fstrhash_lc (str, FALSE);
-			}
-			while (p < end) {
-				uc = g_unichar_tolower (g_utf8_get_char (p));
-				for (j = 0; j < sizeof (gunichar); j++) {
-					t = (uc >> (j * 8)) & 0xff;
-					if (t != 0) {
-						hval = fstrhash_c (t, hval);
-					}
+		if (rspamd_fast_utf8_validate (p, str->len) != 0) {
+			return rspamd_fstrhash_lc (str, FALSE);
+		}
+		while (p < end) {
+			uc = g_unichar_tolower (g_utf8_get_char (p));
+			for (j = 0; j < sizeof (gunichar); j++) {
+				t = (uc >> (j * 8)) & 0xff;
+				if (t != 0) {
+					hval = fstrhash_c (t, hval);
 				}
-				p = g_utf8_next_char (p);
 			}
-			p = end + 1;
+			p = g_utf8_next_char (p);
 		}
-
 	}
 	else {
 		for (i = 0; i < str->len; i++, p++) {
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c
index a1c1f0b20..f15e25399 100644
--- a/src/lua/lua_tcp.c
+++ b/src/lua/lua_tcp.c
@@ -1521,6 +1521,8 @@ lua_tcp_request (lua_State *L)
 				event_loop = *(struct ev_loop **)lua_touserdata (L, -1);
 			}
 			else {
+				g_free (cbd);
+
 				return luaL_error (L, "event loop is required");
 			}
 			lua_pop (L, 1);
@@ -1693,6 +1695,8 @@ lua_tcp_request (lua_State *L)
 
 	if (resolver == NULL && cfg == NULL && task == NULL) {
 		g_free (cbd);
+		g_free (iov);
+
 		return luaL_error (L, "tcp request has bad params: one of "
 						"{resolver,task,config} should be set");
 	}


More information about the Commits mailing list