From: Vsevolod Stakhov Date: Fri, 6 Mar 2015 11:41:28 +0000 (+0000) Subject: m,, regexps are to be treated as strict match. X-Git-Tag: 0.9.0~544 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=99b1a15586c1d84b13a899535612fd0d1a8ec0dc;p=rspamd.git m,, regexps are to be treated as strict match. --- diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c index 3f93051f6..a50148740 100644 --- a/src/libutil/regexp.c +++ b/src/libutil/regexp.c @@ -35,6 +35,7 @@ typedef guchar regexp_id_t[BLAKE2B_OUTBYTES]; #define RSPAMD_REGEXP_FLAG_RAW (1 << 1) #define RSPAMD_REGEXP_FLAG_NOOPT (1 << 2) +#define RSPAMD_REGEXP_FLAG_FULL_MATCH (1 << 3) struct rspamd_regexp_s { gdouble exec_time; @@ -133,11 +134,13 @@ rspamd_regexp_new (const gchar *pattern, const gchar *flags, else if (*start == 'm') { start ++; sep = *start; + rspamd_flags |= RSPAMD_REGEXP_FLAG_FULL_MATCH; } if (sep == '\0' || g_ascii_isalnum (sep)) { /* We have no flags, no separators and just use all line as expr */ start = pattern; end = start + strlen (pattern); + rspamd_flags &= ~RSPAMD_REGEXP_FLAG_FULL_MATCH; } else { end = strrchr (pattern, sep); @@ -159,7 +162,7 @@ rspamd_regexp_new (const gchar *pattern, const gchar *flags, end = pattern + strlen (pattern); } - regexp_flags |= PCRE_UTF8 | PCRE_NO_AUTO_CAPTURE; + regexp_flags |= PCRE_UTF8 ; if (flags != NULL) { flags_str = flags; @@ -366,6 +369,13 @@ rspamd_regexp_search (rspamd_regexp_t *re, const gchar *text, gsize len, *end = mt + ovec[0] + ovec[1]; } + if (re->flags & RSPAMD_REGEXP_FLAG_FULL_MATCH) { + /* We also ensure that the match is full */ + if (ovec[0] != 0 || (guint)ovec[1] < len) { + return FALSE; + } + } + return TRUE; }