diff --git a/src/lib-sieve/sieve-address.c b/src/lib-sieve/sieve-address.c index 3e47a2eeb8e85cc9acd4fb429489e24cbab35762..b13623222d2a8d54ad3536d19ee0bbf9c0219ef2 100644 --- a/src/lib-sieve/sieve-address.c +++ b/src/lib-sieve/sieve-address.c @@ -166,11 +166,11 @@ static int parse_mailbox(struct sieve_message_address_parser *ctx) const unsigned char *start; /* sieve-address = addr-spec ; simple address - * / phrase "<" addr-spec ">" ; name & addr-spec - */ + * / phrase "<" addr-spec ">" ; name & addr-spec + */ - /* Record parser state in case we fail at our first attempt */ - start = ctx->parser.data; + /* Record parser state in case we fail at our first attempt */ + start = ctx->parser.data; /* First try: phrase "<" addr-spec ">" ; name & addr-spec */ str_truncate(ctx->str, 0); @@ -227,6 +227,14 @@ static bool parse_mailbox_address if ((ret = parse_mailbox(ctx)) < 0) { return FALSE; } + + if (ctx->parser.data != ctx->parser.end) { + if ( *ctx->parser.data == ',' ) + sieve_address_error(ctx, "not a single addres (found ',')"); + else + sieve_address_error(ctx, "address ends in invalid characters"); + return FALSE; + } if ( str_len(ctx->domain) == 0 ) { /* Not gonna happen */ @@ -315,7 +323,7 @@ const char *sieve_address_normalize *error_r = NULL; (void)str_lcase(str_c_modifiable(ctx.domain)); - + return t_strconcat(str_c(ctx.local_part), "@", str_c(ctx.domain), NULL); } diff --git a/tests/compile/errors.svtest b/tests/compile/errors.svtest index a5a876882fd18e2110e5b1e9c27e3818e430e8f8..99e48332f5061d0d21d106b60f21d6259e34fc86 100644 --- a/tests/compile/errors.svtest +++ b/tests/compile/errors.svtest @@ -293,7 +293,7 @@ test "Outgoing address errors (FIXME: count only)" { test_fail "compile should have failed."; } - if not test_error :count "eq" :comparator "i;ascii-numeric" "13" { + if not test_error :count "eq" :comparator "i;ascii-numeric" "15" { test_fail "wrong number of errors reported"; } } diff --git a/tests/compile/errors/out-address.sieve b/tests/compile/errors/out-address.sieve index 0c88046aa6535b5567b20ba7be9a94f7f8e998a7..1b06446c0c42af1640c23208fd08b28225f0d08b 100644 --- a/tests/compile/errors/out-address.sieve +++ b/tests/compile/errors/out-address.sieve @@ -1,5 +1,7 @@ require "vacation"; +# Error + redirect "@wrong.example.com"; redirect "error"; redirect "error@"; @@ -11,6 +13,8 @@ redirect "<>"; redirect "Error <"; redirect "Error <stephan"; redirect "Error <stephan@"; +redirect "stephan@rename-it.nl,tss@iki.fi"; +redirect "stephan@rename-it.nl,%&^&!!~"; vacation :from "Error" "Ik ben er niet.";