commit e658c7f: [Fix] Escape utf in regexp to dodge ragel/hyperscan issue

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Jun 4 12:00:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-06-04 10:06:24 +0100
URL: https://github.com/rspamd/rspamd/commit/e658c7fcb5d275f144954b9cea1c34fadfa81902

[Fix] Escape utf in regexp to dodge ragel/hyperscan issue

---
 src/libmime/mime_expressions.c | 7 ++++++-
 src/libutil/str_util.c         | 2 +-
 src/libutil/str_util.h         | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/libmime/mime_expressions.c b/src/libmime/mime_expressions.c
index 7a0c27f1b..89111743b 100644
--- a/src/libmime/mime_expressions.c
+++ b/src/libmime/mime_expressions.c
@@ -491,9 +491,14 @@ rspamd_mime_expr_parse_regexp_atom (rspamd_mempool_t * pool, const gchar *line,
 	dend = result->regexp_text + (end - start);
 	*dend = '\0';
 
-	result->regexp = rspamd_regexp_new (dbegin, re_flags->str,
+	gsize esc_len;
+	gchar *escaped = rspamd_str_regexp_escape (dbegin, dend - dbegin, &esc_len,
+			RSPAMD_REGEXP_ESCAPE_UTF);
+
+	result->regexp = rspamd_regexp_new (escaped, re_flags->str,
 			&err);
 
+	g_free (escaped);
 	g_string_free (re_flags, TRUE);
 
 	if (result->regexp == NULL || err != NULL) {
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index 290110b2b..0c8ff7144 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -2591,7 +2591,7 @@ out:
 
 gchar *
 rspamd_str_regexp_escape (const gchar *pattern, gsize slen,
-		gsize *dst_len, enum rspamd_regexp_escape_flags flags)
+						  gsize *dst_len, enum rspamd_regexp_escape_flags flags)
 {
 	const gchar *p, *end = pattern + slen;
 	gchar *res, *d, t, *tmp_utf = NULL, *dend;
diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h
index 8e8898a32..4a5a8a63a 100644
--- a/src/libutil/str_util.h
+++ b/src/libutil/str_util.h
@@ -466,7 +466,7 @@ enum rspamd_regexp_escape_flags {
  */
 gchar *
 rspamd_str_regexp_escape (const gchar *pattern, gsize slen,
-		gsize *dst_len, enum rspamd_regexp_escape_flags flags);
+						  gsize *dst_len, enum rspamd_regexp_escape_flags flags);
 
 /**
  * Returns copy of src (zero terminated) where all unicode is made valid or replaced


More information about the Commits mailing list