diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-10-17 14:17:00 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-10-17 14:17:00 +0300 |
commit | b441439d550de340e892903b1309fb35bfba6312 (patch) | |
tree | e375e802f6a1173abe9dd29053e1e5ff2aae4123 /src/plugins | |
parent | 350af45ecb3cdd4fc08989ee5365f8e9a5044e83 (diff) | |
download | rspamd-b441439d550de340e892903b1309fb35bfba6312.tar.gz rspamd-b441439d550de340e892903b1309fb35bfba6312.zip |
Check utf8 characters before gregex checks as they assume input to be a utf8 valid string.
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/regexp.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index df3675e93..519666662 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -696,6 +696,13 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task, const gchar while (cur) { debug_task ("found header \"%s\" with value \"%s\"", re->header, (const gchar *)cur->data); /* Try to match regexp */ + if (!re->is_raw) { + /* Validate input */ + if (!g_utf8_validate (cur->data, -1, NULL)) { + cur = g_list_next (cur); + continue; + } + } if (cur->data && g_regex_match_full (re->regexp, cur->data, -1, 0, 0, NULL, &err) == TRUE) { if (G_UNLIKELY (re->is_test)) { msg_info ("process test regexp %s for header %s with value '%s' returned TRUE", re->regexp_text, re->header, (const gchar *)cur->data); @@ -746,6 +753,7 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task, const gchar regexp = re->raw_regexp; } else { + /* This time there is no need to validate anything as conversion succeed only for valid characters */ regexp = re->regexp; } /* Select data for regexp */ @@ -913,6 +921,13 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task, const gchar debug_task ("found header \"%s\" with value \"%s\"", re->header, (const gchar *)cur->data); rh = cur->data; /* Try to match regexp */ + if (!re->is_raw) { + /* Validate input */ + if (!g_utf8_validate (rh->value, -1, NULL)) { + cur = g_list_next (cur); + continue; + } + } if (rh->value && g_regex_match_full (re->regexp, rh->value, -1, 0, 0, NULL, &err) == TRUE) { if (G_UNLIKELY (re->is_test)) { msg_info ("process test regexp %s for header %s with value '%s' returned TRUE", re->regexp_text, re->header, (const gchar *)cur->data); |