]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: Fixed message_parser_init_from_parts() with truncated MIME headers
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 11 Jun 2016 18:23:07 +0000 (21:23 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 14 Jun 2016 09:25:28 +0000 (12:25 +0300)
src/lib-mail/message-parser.c

index b31b494e757605cc33145d9027043de9804e9035..20ad10272565047c44c9f465689aaeef00a99596 100644 (file)
@@ -1005,14 +1005,22 @@ static int preparsed_parse_next_header(struct message_parser_ctx *ctx,
 static int preparsed_parse_next_header_init(struct message_parser_ctx *ctx,
                                            struct message_block *block_r)
 {
+       struct istream *hdr_input;
+
        i_assert(ctx->hdr_parser_ctx == NULL);
 
        i_assert(ctx->part->physical_pos >= ctx->input->v_offset);
        i_stream_skip(ctx->input, ctx->part->physical_pos -
                      ctx->input->v_offset);
 
+       /* the header may become truncated by --boundaries. limit the header
+          stream's size to what it's supposed to be to avoid duplicating (and
+          keeping in sync!) all the same complicated logic as in
+          parse_next_header(). */
+       hdr_input = i_stream_create_limit(ctx->input, ctx->part->header_size.physical_size);
        ctx->hdr_parser_ctx =
-               message_parse_header_init(ctx->input, NULL, ctx->hdr_flags);
+               message_parse_header_init(hdr_input, NULL, ctx->hdr_flags);
+       i_stream_unref(&hdr_input);
 
        ctx->parse_next_block = preparsed_parse_next_header;
        return preparsed_parse_next_header(ctx, block_r);