Skip to content
Snippets Groups Projects
Commit 9845a640 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Forgot to handle stringlists in :regex validation.

parent 9d4dce9c
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "sieve-interpreter.h" #include "sieve-interpreter.h"
#include <sys/types.h> #include <sys/types.h>
#include <ctype.h>
#include <regex.h> #include <regex.h>
/* Forward declarations */ /* Forward declarations */
...@@ -110,13 +111,31 @@ static const char *_regexp_error(regex_t *regexp, int errorcode) ...@@ -110,13 +111,31 @@ static const char *_regexp_error(regex_t *regexp, int errorcode)
return ""; return "";
} }
static bool mtch_regex_validate_regexp
(struct sieve_validator *validator, struct sieve_match_type_context *ctx,
struct sieve_ast_argument *key, int cflags)
{
int ret;
regex_t regexp;
if ( (ret=regcomp(&regexp, sieve_ast_argument_strc(key), cflags)) != 0 ) {
sieve_command_validate_error(validator, ctx->command_ctx,
"invalid regular expression for regex match: %s",
_regexp_error(&regexp, ret));
regfree(&regexp);
return FALSE;
}
regfree(&regexp);
return TRUE;
}
bool mtch_regex_validate_context bool mtch_regex_validate_context
(struct sieve_validator *validator, struct sieve_ast_argument *arg, (struct sieve_validator *validator, struct sieve_ast_argument *arg,
struct sieve_match_type_context *ctx, struct sieve_ast_argument *key_arg) struct sieve_match_type_context *ctx, struct sieve_ast_argument *key_arg)
{ {
bool result = TRUE; int cflags;
int ret, cflags;
regex_t regexp;
struct sieve_ast_argument *carg = struct sieve_ast_argument *carg =
sieve_command_first_argument(ctx->command_ctx); sieve_command_first_argument(ctx->command_ctx);
...@@ -140,15 +159,26 @@ bool mtch_regex_validate_context ...@@ -140,15 +159,26 @@ bool mtch_regex_validate_context
carg = sieve_ast_argument_next(carg); carg = sieve_ast_argument_next(carg);
} }
if ( (ret=regcomp(&regexp, sieve_ast_argument_strc(key_arg), cflags)) != 0 ) { /* Validate regular expression(s) */
sieve_command_validate_error(validator, ctx->command_ctx, if ( sieve_ast_argument_type(key_arg) == SAAT_STRING ) {
"invalid regular expression for regex match: %s", /* Single string */
_regexp_error(&regexp, ret)); if ( !mtch_regex_validate_regexp(validator, ctx, key_arg, cflags) )
return FALSE;
result = FALSE;
}
regfree(&regexp); } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) {
/* String list */
struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg);
while ( stritem != NULL ) {
if ( !mtch_regex_validate_regexp(validator, ctx, stritem, cflags) )
return FALSE;
stritem = sieve_ast_strlist_next(stritem);
}
} else {
/* ??? */
return FALSE;
}
return TRUE; return TRUE;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.