]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix one character length substrings search
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Apr 2017 15:02:52 +0000 (16:02 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Apr 2017 15:05:35 +0000 (16:05 +0100)
src/libutil/str_util.c

index f3e4a1f8c641d1084ba861d7ca2b7dfc854fac25..595eca2f62b1b80479dfd18df5c6c50e2e9227db 100644 (file)
@@ -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);
        }