From: Timo Sirainen Date: Wed, 30 Dec 2015 13:21:46 +0000 (-0500) Subject: lib-mail: message-parser wasn't returning hdr=NULL blocks after 078c2c8c X-Git-Tag: 2.2.22.rc1~393 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a4392e9d312e3b5973fe5dbaee7028197a700ff0;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: message-parser wasn't returning hdr=NULL blocks after 078c2c8c --- diff --git a/src/lib-mail/message-parser.c b/src/lib-mail/message-parser.c index 3d65ad9d8a..e5ad128cdf 100644 --- a/src/lib-mail/message-parser.c +++ b/src/lib-mail/message-parser.c @@ -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); diff --git a/src/lib-mail/test-message-parser.c b/src/lib-mail/test-message-parser.c index 671fd50882..a862427e94 100644 --- a/src/lib-mail/test-message-parser.c +++ b/src/lib-mail/test-message-parser.c @@ -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);