Skip to content

Commit

Permalink
lib-mail: rfc822-parser: Don't allow preserving escaped [CR]LF
Browse files Browse the repository at this point in the history
It's not valid to have "\<CR>" or "\<LF>", so the old behavior isn't really
wrong either. However, rfc822_parse_quoted_string() callers are more likely
to expect that the output won't contain any [CR]LF so this new behavior is
a bit better.
  • Loading branch information
sirainen committed Aug 30, 2018
1 parent 6cc952b commit c98c10e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/lib-mail/rfc822-parser.c
Expand Up @@ -234,6 +234,13 @@ int rfc822_parse_quoted_string(struct rfc822_parser_context *ctx, string_t *str)
if (ctx->data >= ctx->end)
return -1;

if (*ctx->data == '\r' || *ctx->data == '\n') {
/* quoted-pair doesn't allow CR/LF.
They are part of the obs-qp though, so don't
return them as error. */
ctx->data--;
break;
}
str_append_data(str, start, ctx->data - start - 1);
start = ctx->data;
break;
Expand Down
6 changes: 5 additions & 1 deletion src/lib-mail/test-rfc822-parser.c
Expand Up @@ -18,7 +18,11 @@ static void test_rfc822_parse_quoted_string(void)
{ "\"\"\"", "", 1 },
{ "\"\\\"\"", "\"", 0 },
{ "\"\\\\\"", "\\", 0 },
{ "\"\\\\foo\\\\foo\\\\\"", "\\foo\\foo\\", 0 }
{ "\"\\\\foo\\\\foo\\\\\"", "\\foo\\foo\\", 0 },
{ "\"foo\n bar\"", "foo bar", 0 },
{ "\"foo\n\t\t bar\"", "foo\t\t bar", 0 },
{ "\"foo\\\n bar\"", "foo\\ bar", 0 },
{ "\"foo\\\r\n bar\"", "foo\\ bar", 0 },
};
struct rfc822_parser_context parser;
string_t *str = t_str_new(64);
Expand Down

0 comments on commit c98c10e

Please sign in to comment.