diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-07-15 20:02:28 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-07-15 20:02:28 +0100 |
commit | ff54c0e7314e77f6031a2ce438d38522ac7ca5e5 (patch) | |
tree | c995927acc94e812f06670fde90f088b9cc13bba | |
parent | b4679a32d4a586200399d941fa1acc982deeb98c (diff) | |
download | rspamd-ff54c0e7314e77f6031a2ce438d38522ac7ca5e5.tar.gz rspamd-ff54c0e7314e77f6031a2ce438d38522ac7ca5e5.zip |
[Minor] Fix regexps parsing
-rw-r--r-- | src/libutil/regexp.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c index c9e832929..e9934083d 100644 --- a/src/libutil/regexp.c +++ b/src/libutil/regexp.c @@ -309,7 +309,7 @@ rspamd_regexp_t* rspamd_regexp_new_len (const gchar *pattern, gsize len, const gchar *flags, GError **err) { - const gchar *start = pattern, *end = start + len, *flags_str = NULL; + const gchar *start = pattern, *end = start + len, *flags_str = NULL, *flags_end; gchar *err_str; rspamd_regexp_t *res; gboolean explicit_utf = FALSE; @@ -347,21 +347,23 @@ rspamd_regexp_new_len (const gchar *pattern, gsize len, const gchar *flags, rspamd_flags |= RSPAMD_REGEXP_FLAG_FULL_MATCH; } - if (g_ascii_isalnum (sep)) { + if (sep == 0) { /* We have no flags, no separators and just use all line as expr */ start = pattern; rspamd_flags &= ~RSPAMD_REGEXP_FLAG_FULL_MATCH; } else { - end = rspamd_memrchr(pattern, sep, len); + gchar *last_sep = rspamd_memrchr(pattern, sep, len); - if (end == NULL || end <= start) { + if (last_sep == NULL || last_sep <= start) { g_set_error (err, rspamd_regexp_quark(), EINVAL, "pattern is not enclosed with %c: %s", sep, pattern); return NULL; } - flags_str = end + 1; + flags_str = last_sep + 1; + flags_end = end; + end = last_sep; start ++; } } @@ -370,6 +372,7 @@ rspamd_regexp_new_len (const gchar *pattern, gsize len, const gchar *flags, strict_flags = TRUE; start = pattern; flags_str = flags; + flags_end = flags + strlen(flags); } rspamd_flags |= RSPAMD_REGEXP_FLAG_RAW; @@ -382,7 +385,7 @@ rspamd_regexp_new_len (const gchar *pattern, gsize len, const gchar *flags, #endif if (flags_str != NULL) { - while (flags_str < end) { + while (flags_str < flags_end) { switch (*flags_str) { case 'i': regexp_flags |= PCRE_FLAG(CASELESS); |