commit 416da19: [Minor] Some minor cleanups

Vsevolod Stakhov vsevolod at highsecure.ru
Sun Sep 19 11:14:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-09-19 10:30:39 +0100
URL: https://github.com/rspamd/rspamd/commit/416da198db9ca6bff6859eb52bd61ad5c261bddd

[Minor] Some minor cleanups
Found by: coverity scan

---
 src/libserver/dkim.c        |  5 +++--
 src/libserver/dns.c         | 12 ++++++------
 src/libserver/html/html.cxx | 10 +++++-----
 src/libserver/milter.c      |  2 +-
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c
index 01bea2d56..762bbaa94 100644
--- a/src/libserver/dkim.c
+++ b/src/libserver/dkim.c
@@ -1117,7 +1117,7 @@ rspamd_create_dkim_context (const gchar *sig,
 			}
 			else {
 				msg_info_dkim ("dkim parse failed: unknown error when parsing %c tag",
-						*tag);
+						tag ? *tag : '?');
 				return NULL;
 			}
 			break;
@@ -2639,7 +2639,8 @@ rspamd_dkim_check (rspamd_dkim_context_t *ctx,
 	}
 
 
-	if (ctx->common.type != RSPAMD_DKIM_ARC_SEAL) {
+	/* Use cached BH for all but arc seal, if it is not NULL we are not in arc seal mode */
+	if (cached_bh != NULL) {
 		if (!cached_bh->digest_normal) {
 			/* Copy md_ctx to deal with broken CRLF at the end */
 			cpy_ctx = EVP_MD_CTX_create ();
diff --git a/src/libserver/dns.c b/src/libserver/dns.c
index 0eff240a6..eb694a74d 100644
--- a/src/libserver/dns.c
+++ b/src/libserver/dns.c
@@ -432,6 +432,12 @@ rspamd_dns_server_init (struct upstream *up, guint idx, gpointer ud)
 	if (r->cfg) {
 		serv = rdns_resolver_add_server (r->r, rspamd_inet_address_to_string (addr),
 				rspamd_inet_address_get_port (addr), 0, r->cfg->dns_io_per_server);
+
+		elt = rspamd_mempool_alloc0 (r->cfg->cfg_pool, sizeof (*elt));
+		elt->server = serv;
+		elt->lib_data = up;
+
+		rspamd_upstream_set_data (up, elt);
 	}
 	else {
 		serv = rdns_resolver_add_server (r->r, rspamd_inet_address_to_string (addr),
@@ -439,12 +445,6 @@ rspamd_dns_server_init (struct upstream *up, guint idx, gpointer ud)
 	}
 
 	g_assert (serv != NULL);
-
-	elt = rspamd_mempool_alloc0 (r->cfg->cfg_pool, sizeof (*elt));
-	elt->server = serv;
-	elt->lib_data = up;
-
-	rspamd_upstream_set_data (up, elt);
 }
 
 static void
diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index b9729a71e..c3485b099 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -174,22 +174,22 @@ html_check_balance(struct html_content *hc,
 		 */
 
 		if (hc->all_tags.empty()) {
-			auto &&vtag = std::make_unique<html_tag>();
+			hc->all_tags.emplace_back();
+			auto *vtag = hc->all_tags.back().get();
 			vtag->id = Tag_HTML;
 			vtag->flags = FL_VIRTUAL;
 			vtag->tag_start = 0;
 			vtag->content_offset = 0;
-			calculate_content_length(vtag.get());
+			calculate_content_length(vtag);
 
 			if (!hc->root_tag) {
-				hc->root_tag = vtag.get();
+				hc->root_tag = vtag;
 			}
 			else {
 				vtag->parent = hc->root_tag;
 			}
 
-			hc->all_tags.emplace_back(std::move(vtag));
-			tag->parent = vtag.get();
+			tag->parent = vtag;
 
 			/* Recursively call with a virtual <html> tag inserted */
 			return html_check_balance(hc, tag, tag_start_offset, tag_end_offset);
diff --git a/src/libserver/milter.c b/src/libserver/milter.c
index 97e448794..301c26a1f 100644
--- a/src/libserver/milter.c
+++ b/src/libserver/milter.c
@@ -908,8 +908,8 @@ rspamd_milter_consume_input (struct rspamd_milter_session *session,
 					 * In general, don't use it for anything but ping checks
 					 */
 					memset (&http_callbacks, 0, sizeof (http_callbacks));
-					http_parser_init (&http_parser, HTTP_REQUEST);
 					http_parser.data = url;
+					http_parser_init (&http_parser, HTTP_REQUEST);
 					http_callbacks.on_url = rspamd_milter_http_on_url;
 					http_parser_execute (&http_parser, &http_callbacks,
 							priv->parser.buf->str, priv->parser.buf->len);


More information about the Commits mailing list