From d22abb557ecda41ab076b4c777dfd4c95340fbfd Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 21 Oct 2019 14:44:07 +0100 Subject: [PATCH] [Minor] Fix utf8 regexps escaping --- src/libutil/str_util.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index f5cd8be1a..f325b35f6 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -2725,7 +2725,7 @@ rspamd_str_regexp_escape (const gchar *pattern, gsize slen, gsize len; static const gchar hexdigests[16] = "0123456789abcdef"; - len = slen; + len = 0; p = pattern; /* [-[\]{}()*+?.,\\^$|#\s] need to be escaped */ @@ -2781,13 +2781,10 @@ rspamd_str_regexp_escape (const gchar *pattern, gsize slen, } } - if (slen == len) { - if (dst_len) { - - if (tmp_utf) { - slen = strlen (tmp_utf); - } + if (len == 0) { + /* No need to escape anything */ + if (dst_len) { *dst_len = slen; } @@ -2799,10 +2796,12 @@ rspamd_str_regexp_escape (const gchar *pattern, gsize slen, } } + /* Escape logic */ if (tmp_utf) { pattern = tmp_utf; } + len = slen + len; res = g_malloc (len + 1); p = pattern; d = res; -- 2.39.5