From c1cce962177242f408040e422741bd30a61ff0f1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 7 Apr 2017 16:02:52 +0100 Subject: [PATCH] [Fix] Fix one character length substrings search --- src/libutil/str_util.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index f3e4a1f8c..595eca2f6 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -1288,6 +1288,18 @@ rspamd_substring_search (const gchar *in, gsize inlen, const gchar *srch, gsize srchlen) { if (inlen > srchlen) { + if (G_UNLIKELY (srchlen == 1)) { + const gchar *p; + + p = memchr (in, srch[0], inlen); + + if (p) { + return p - in; + } + + return (-1); + } + return rspamd_substring_search_common (in, inlen, srch, srchlen, rspamd_substring_cmp_func); } @@ -1306,6 +1318,19 @@ rspamd_substring_search_caseless (const gchar *in, gsize inlen, const gchar *srch, gsize srchlen) { if (inlen > srchlen) { + if (G_UNLIKELY (srchlen == 1)) { + goffset i; + gchar s = lc_map[(guchar)srch[0]]; + + for (i = 0; i < inlen; i++) { + if (lc_map[(guchar)in[i]] == s) { + return i; + } + } + + return (-1); + } + return rspamd_substring_search_common (in, inlen, srch, srchlen, rspamd_substring_casecmp_func); } -- 2.39.5