aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-06 11:41:28 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-06 11:41:28 +0000
commit99b1a15586c1d84b13a899535612fd0d1a8ec0dc (patch)
tree7fb7d4bb33353b86fc5437eb7719fb87bb1e0b1b
parent5bce9da91161ad1a3b9f6ce3403d58b1048d8c35 (diff)
downloadrspamd-99b1a15586c1d84b13a899535612fd0d1a8ec0dc.tar.gz
rspamd-99b1a15586c1d84b13a899535612fd0d1a8ec0dc.zip
m,, regexps are to be treated as strict match.
-rw-r--r--src/libutil/regexp.c12
1 files changed, 11 insertions, 1 deletions
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;
}