]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: rfc822-parser: Don't allow preserving escaped [CR]LF
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 21 Apr 2018 10:05:49 +0000 (13:05 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 30 Aug 2018 08:13:01 +0000 (11:13 +0300)
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.

src/lib-mail/rfc822-parser.c
src/lib-mail/test-rfc822-parser.c

index 917288cda72191c3836105b353bab778b99b7da9..2f7e77da9cc5282b2af9e4fed48da9008a16f765 100644 (file)
@@ -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;
index 695021f1e5c30da46fd023335579ca7a484056b9..8f8d4fb66b83a3822db3cf39d11ae2cad0e7715f 100644 (file)
@@ -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);