commit cf071c7: [Minor] Fix some more issues

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Sep 25 12:07:06 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-09-25 12:45:29 +0100
URL: https://github.com/rspamd/rspamd/commit/cf071c74aa8e7d2975b08a1271902401890c41f7

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

---
 src/controller.c           |  2 ++
 src/libserver/maps/map.c   |  8 ++++++++
 src/libserver/re_cache.c   |  7 +++++--
 src/libutil/addr.c         | 34 ++++++++++++++++++++++++++++++----
 src/libutil/sqlite_utils.c |  2 +-
 5 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/src/controller.c b/src/controller.c
index 34685b92e..26fd1c9de 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -340,6 +340,8 @@ check_uncached:
 			/* We have some unknown salt here */
 			msg_info_ctx ("incorrect salt: %z, while %z expected",
 					salt_len, pbkdf->salt_len);
+			g_free (salt_decoded);
+
 			return FALSE;
 		}
 
diff --git a/src/libserver/maps/map.c b/src/libserver/maps/map.c
index eaf7958f8..d30b2b40d 100644
--- a/src/libserver/maps/map.c
+++ b/src/libserver/maps/map.c
@@ -2661,6 +2661,14 @@ err:
 		g_free (hdata);
 	}
 
+	if (fdata) {
+		g_free (fdata);
+	}
+
+	if (sdata) {
+		g_free (sdata);
+	}
+
 	return NULL;
 }
 
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index 4d631da01..82bbcee1c 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -1889,7 +1889,7 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
 	guint *hs_flags = NULL;
 	const hs_expr_ext_t **hs_exts = NULL;
 	gchar **hs_pats = NULL;
-	gchar *hs_serialized;
+	gchar *hs_serialized = NULL;
 	gsize serialized_len;
 	struct iovec iov[7];
 	struct rspamd_re_cache *cache;
@@ -1918,7 +1918,7 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
 
 		/* Read number of regexps */
 		g_assert (fd != -1);
-		lseek (fd, RSPAMD_HS_MAGIC_LEN + sizeof (cache->plt), SEEK_SET);
+		g_assert (lseek (fd, RSPAMD_HS_MAGIC_LEN + sizeof (cache->plt), SEEK_SET) != -1);
 		g_assert (read (fd, &n, sizeof (n)) == sizeof (n));
 		close (fd);
 
@@ -2212,6 +2212,9 @@ rspamd_re_cache_compile_timer_cb (EV_P_ ev_timer *w, int revents )
 				(gint)g_hash_table_size (re_class->re),
 				path);
 
+		g_free (hs_serialized);
+		g_free (hs_ids);
+		g_free (hs_flags);
 		unlink (path);
 		close (fd);
 		rspamd_re_cache_compile_err (EV_A_ w, err, cbdata);
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index fd628aaca..b19182514 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -336,6 +336,12 @@ rspamd_parse_unix_path (rspamd_inet_addr_t **target,
 		tokens = rspamd_string_len_split (src, len, " ,", -1, pool);
 
 		if (tokens[0] == NULL) {
+
+			if (!pool) {
+				rspamd_inet_address_free(addr);
+				g_strfreev (tokens);
+			}
+
 			return FALSE;
 		}
 
@@ -351,6 +357,17 @@ rspamd_parse_unix_path (rspamd_inet_addr_t **target,
 #if defined(FREEBSD) || defined(__APPLE__)
 		addr->u.un->addr.sun_len = SUN_LEN (&addr->u.un->addr);
 #endif
+
+		if (target) {
+			rspamd_ip_validate_af (addr);
+			*target = addr;
+		}
+		else {
+			if (!pool) {
+				rspamd_inet_address_free(addr);
+			}
+		}
+
 		return TRUE;
 	}
 
@@ -415,24 +432,29 @@ rspamd_parse_unix_path (rspamd_inet_addr_t **target,
 	}
 
 	g_free (pwbuf);
-	g_strfreev (tokens);
+
+	if (!pool) {
+		g_strfreev(tokens);
+	}
 
 	if (target) {
 		rspamd_ip_validate_af (addr);
 		*target = addr;
 	}
 	else {
-		rspamd_inet_address_free (addr);
+		if (!pool) {
+			rspamd_inet_address_free(addr);
+		}
 	}
 
 	return TRUE;
 
 err:
 
-	g_strfreev (tokens);
 	g_free (pwbuf);
 
 	if (!pool) {
+		g_strfreev(tokens);
 		rspamd_inet_address_free (addr);
 	}
 
@@ -1302,7 +1324,7 @@ rspamd_resolve_addrs (const char *begin, size_t len, GPtrArray **addrs,
 	rspamd_ip_check_ipv6 ();
 
 	if (rspamd_parse_inet_address (&cur_addr,
-			begin, len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
+			begin, len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT) && cur_addr != NULL) {
 		if (*addrs == NULL) {
 			*addrs = g_ptr_array_new_full (1,
 					(GDestroyNotify) rspamd_inet_address_free);
@@ -1391,6 +1413,10 @@ rspamd_resolve_addrs (const char *begin, size_t len, GPtrArray **addrs,
 		}
 	}
 
+	if (pool == NULL) {
+		g_free (addr_cpy);
+	}
+
 	return ret;
 }
 
diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c
index f9e47032c..9bb0b9c1f 100644
--- a/src/libutil/sqlite_utils.c
+++ b/src/libutil/sqlite_utils.c
@@ -356,7 +356,7 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
 	else {
 		pid_t myself = getpid ();
 		msg_debug_pool_check ("locking %s to block other processes", lock_path);
-		(void) !write (lock_fd, &myself, sizeof (myself));
+		(void)write (lock_fd, &myself, sizeof (myself));
 
 		g_assert (rspamd_file_lock (lock_fd, FALSE));
 		has_lock = TRUE;


More information about the Commits mailing list