commit d46799f: [Minor] Always report multipattern compile error

Vsevolod Stakhov vsevolod at rspamd.com
Thu May 18 19:35:03 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-05-18 20:28:21 +0100
URL: https://github.com/rspamd/rspamd/commit/d46799f2874622e356fe263aa9fbda99156247f2 (HEAD -> master)

[Minor] Always report multipattern compile error
Issue: #4487

---
 src/libmime/message.c     | 9 ++++++++-
 src/libmime/mime_parser.c | 8 +++++++-
 src/libserver/url.c       | 2 +-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/libmime/message.c b/src/libmime/message.c
index ad2cccf92..af8ad0e56 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -666,7 +666,14 @@ rspamd_check_gtube (struct rspamd_task *task, struct rspamd_mime_text_part *part
 				gtube_pattern_no_action,
 				RSPAMD_MULTIPATTERN_DEFAULT);
 
-		g_assert (rspamd_multipattern_compile (gtube_matcher, NULL));
+		GError *err = NULL;
+		rspamd_multipattern_compile (gtube_matcher, &err);
+
+		if (err != NULL) {
+			/* It will be expensive, but I don't care, still better than to abort */
+			msg_err ("cannot compile gtube matcher: %s", err->message);
+			g_error_free (err);
+		}
 	}
 
 	if (part->utf_content.len >= sizeof (gtube_pattern_reject) &&
diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c
index 538c05735..48b946d8f 100644
--- a/src/libmime/mime_parser.c
+++ b/src/libmime/mime_parser.c
@@ -167,7 +167,13 @@ rspamd_mime_parser_init_lib (void)
 	g_assert (lib_ctx->mp_boundary != NULL);
 	rspamd_multipattern_add_pattern (lib_ctx->mp_boundary, "\r--", 0);
 	rspamd_multipattern_add_pattern (lib_ctx->mp_boundary, "\n--", 0);
-	g_assert (rspamd_multipattern_compile (lib_ctx->mp_boundary, NULL));
+
+	GError *err = NULL;
+	if (!rspamd_multipattern_compile (lib_ctx->mp_boundary, &err)) {
+		msg_err ("fatal error: cannot compile multipattern for mime parser boundaries: %e", err);
+		g_error_free (err);
+		g_abort();
+	}
 	ottery_rand_bytes (lib_ctx->hkey, sizeof (lib_ctx->hkey));
 }
 
diff --git a/src/libserver/url.c b/src/libserver/url.c
index 2ae50b95b..824dc05cc 100644
--- a/src/libserver/url.c
+++ b/src/libserver/url.c
@@ -630,7 +630,7 @@ rspamd_url_init (const gchar *tld_file)
 	if (url_scanner->search_trie_full) {
 		if (!rspamd_multipattern_compile (url_scanner->search_trie_full, &err)) {
 			msg_err ("cannot compile tld patterns, url matching will be "
-					 "broken completely: %e", err);
+					 "incomplete: %e", err);
 			g_error_free (err);
 			ret = FALSE;
 		}


More information about the Commits mailing list