Skip to content

Commit

Permalink
lib-mail: rfc822-parser - Handle \<NUL> in quoted-string and domain-l…
Browse files Browse the repository at this point in the history
…iteral

It was already handled in comments. Previously this caused the strings and
domain-literals to be truncated at that position.
  • Loading branch information
sirainen committed Aug 17, 2018
1 parent 6591014 commit 010a141
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/lib-mail/rfc822-parser.c
Expand Up @@ -273,8 +273,9 @@ 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.
if (*ctx->data == '\r' || *ctx->data == '\n' ||
*ctx->data == '\0') {
/* quoted-pair doesn't allow CR/LF/NUL.
They are part of the obs-qp though, so don't
return them as error. */
ctx->data--;
Expand Down Expand Up @@ -394,8 +395,9 @@ rfc822_parse_domain_literal(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.
if (*ctx->data == '\r' || *ctx->data == '\n' ||
*ctx->data == '\0') {
/* quoted-pair doesn't allow CR/LF/NUL.
They are part of the obs-qp though, so don't
return them as error. */
str_append_data(str, start, ctx->data - start);
Expand Down
14 changes: 8 additions & 6 deletions src/lib-mail/test-message-address.c
Expand Up @@ -325,10 +325,11 @@ static void test_message_address(void)
static void test_message_address_nuls(void)
{
const unsigned char input[] =
"\"user\0nuls\"@[domain\0nuls] (comment\0nuls)";
"\"user\0nuls\\\0-esc\"@[domain\0nuls\\\0-esc] (comment\0nuls\\\0-esc)";
const struct message_address output = {
NULL, "comment\xEF\xBF\xBDnuls", NULL, "user\xEF\xBF\xBDnuls",
"[domain\xEF\xBF\xBDnuls]", FALSE
NULL, "comment\xEF\xBF\xBDnuls\\\xEF\xBF\xBD-esc", NULL,
"user\xEF\xBF\xBDnuls\\\xEF\xBF\xBD-esc",
"[domain\xEF\xBF\xBDnuls\\\xEF\xBF\xBD-esc]", FALSE
};
const struct message_address *addr;

Expand All @@ -342,10 +343,11 @@ static void test_message_address_nuls(void)
static void test_message_address_nuls_display_name(void)
{
const unsigned char input[] =
"\"displayname\0nuls\" <\"user\0nuls\"@[domain\0nuls]>";
"\"displayname\0nuls\\\0-esc\" <\"user\0nuls\\\0-esc\"@[domain\0nuls\\\0-esc]>";
const struct message_address output = {
NULL, "displayname\xEF\xBF\xBDnuls", NULL, "user\xEF\xBF\xBDnuls",
"[domain\xEF\xBF\xBDnuls]", FALSE
NULL, "displayname\xEF\xBF\xBDnuls\\\xEF\xBF\xBD-esc", NULL,
"user\xEF\xBF\xBDnuls\\\xEF\xBF\xBD-esc",
"[domain\xEF\xBF\xBDnuls\\\xEF\xBF\xBD-esc]", FALSE
};
const struct message_address *addr;

Expand Down

0 comments on commit 010a141

Please sign in to comment.