Skip to content

Commit

Permalink
lib-mail: message-parser wasn't returning hdr=NULL blocks after 078c2c8
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Dec 30, 2015
1 parent 4b99408 commit a4392e9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib-mail/message-parser.c
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/lib-mail/test-message-parser.c
Expand Up @@ -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);
Expand Down

0 comments on commit a4392e9

Please sign in to comment.