]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message-snippet - Quoted text could have been wrongly added to the snippet
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 25 Feb 2020 15:33:30 +0000 (17:33 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 26 Feb 2020 08:14:23 +0000 (10:14 +0200)
This happened when the mail was large enough that the parsing used multiple
blocks. Parsing the following blocks were adding text in quoted state to
the non-quoted snippet string.

src/lib-mail/message-snippet.c
src/lib-mail/test-message-snippet.c

index a4ab7b11d68de6cab9bed86b9de992e2e723398f..2100b70554f09b303fd4d2452a011761d09682bb 100644 (file)
@@ -81,7 +81,7 @@ static bool snippet_generate(struct snippet_context *ctx,
                             const unsigned char *data, size_t size)
 {
        size_t i, count;
-       struct snippet_data *target = &ctx->snippet;
+       struct snippet_data *target;
 
        if (ctx->html2text != NULL) {
                buffer_set_used_size(ctx->plain_output, 0);
@@ -91,6 +91,11 @@ static bool snippet_generate(struct snippet_context *ctx,
                size = ctx->plain_output->used;
        }
 
+       if (ctx->state == SNIPPET_STATE_QUOTED)
+               target = &ctx->quoted_snippet;
+       else
+               target = &ctx->snippet;
+
        /* message-decoder should feed us only valid and complete
           UTF-8 input */
 
index b874280cbc921ae338974802c2c9decfcfe7fbec..af96e13e573328d208007fa7b46b29de136019d8 100644 (file)
@@ -133,7 +133,12 @@ static void test_message_snippet(void)
        test_begin("message snippet");
        for (i = 0; i < N_ELEMENTS(tests); i++) {
                str_truncate(str, 0);
-               input = i_stream_create_from_data(tests[i].input, strlen(tests[i].input));
+               input = test_istream_create(tests[i].input);
+               /* Limit the input max buffer size so the parsing uses multiple
+                  blocks. 45 = large enough to be able to read the Content-*
+                  headers. */
+               test_istream_set_max_buffer_size(input,
+                       I_MIN(45, strlen(tests[i].input)));
                test_assert_idx(message_snippet_generate(input, tests[i].max_snippet_chars, str) == 0, i);
                test_assert_idx(strcmp(tests[i].output, str_c(str)) == 0, i);
                i_stream_destroy(&input);