From: Vsevolod Stakhov Date: Fri, 7 Apr 2017 15:02:52 +0000 (+0100) Subject: [Fix] Fix one character length substrings search X-Git-Tag: 1.5.5~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c1cce962177242f408040e422741bd30a61ff0f1;p=rspamd.git [Fix] Fix one character length substrings search --- 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); }