]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message-parser wasn't returning hdr=NULL blocks after 078c2c8c
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 30 Dec 2015 13:21:46 +0000 (08:21 -0500)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 30 Dec 2015 13:21:46 +0000 (08:21 -0500)
src/lib-mail/message-parser.c
src/lib-mail/test-message-parser.c

index 3d65ad9d8ae0f3c66500831c93dfbe7c9a35aaa5..e5ad128cdfaa582051e3148d3865a0dbc23c7195 100644 (file)
@@ -516,14 +516,16 @@ static int parse_next_header(struct message_parser_ctx *ctx,
        bool full;
        int ret;
 
-       if ((ret = message_parser_read_more(ctx, block_r, &full)) <= 0)
+       if ((ret = message_parser_read_more(ctx, block_r, &full)) == 0)
                return ret;
 
        /* before parsing the header see if we can find a --boundary from here.
           we're guaranteed to be at the beginning of the line here. */
-       ret = ctx->boundaries == NULL ? -1 :
-               boundary_line_find(ctx, block_r->data,
-                                  block_r->size, full, &boundary);
+       if (ret > 0) {
+               ret = ctx->boundaries == NULL ? -1 :
+                       boundary_line_find(ctx, block_r->data,
+                                          block_r->size, full, &boundary);
+       }
        if (ret < 0) {
                /* no boundary */
                ret = message_parse_header_next(ctx->hdr_parser_ctx, &hdr);
index 671fd508821e1655bf0ce6d3cf56f2d4559d87ef..a862427e94f4e2741446450a91ccc0d35fb8593a 100644 (file)
@@ -181,11 +181,39 @@ static const char input_msg[] =
        test_end();
 }
 
+static void test_message_parser_no_eoh(void)
+{
+       static const char input_msg[] = "a:b\n";
+       struct message_parser_ctx *parser;
+       struct istream *input;
+       struct message_part *parts;
+       struct message_block block;
+       pool_t pool;
+
+       test_begin("message parser no EOH");
+       pool = pool_alloconly_create("message parser", 10240);
+       input = test_istream_create(input_msg);
+
+       parser = message_parser_init(pool, input, 0, 0);
+       test_assert(message_parser_parse_next_block(parser, &block) > 0 &&
+                   block.hdr != NULL && strcmp(block.hdr->name, "a") == 0 &&
+                   block.hdr->value_len == 1 && block.hdr->value[0] == 'b');
+       test_assert(message_parser_parse_next_block(parser, &block) > 0 &&
+                   block.hdr == NULL && block.size == 0);
+       test_assert(message_parser_parse_next_block(parser, &block) < 0);
+       test_assert(message_parser_deinit(&parser, &parts) == 0);
+
+       i_stream_unref(&input);
+       pool_unref(&pool);
+       test_end();
+}
+
 int main(void)
 {
        static void (*test_functions[])(void) = {
                test_message_parser_small_blocks,
                test_message_parser_truncated_mime_headers,
+               test_message_parser_no_eoh,
                NULL
        };
        return test_run(test_functions);