From 70612e07102b75a8511aa7f9de60771176b18de0 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 25 Sep 2014 00:42:56 +0300 Subject: [PATCH] lib-storage: Headers were sometimes added to dovecot.index.cache with wrong line number value. This happened if the header parsing was done multiple times for the same mail. The end result being that when fetching multiple headers as a stream, the headers could have been returned in the wrong order. This messed up at least dsync's header hash comparisons. --- src/lib-storage/index/index-mail-headers.c | 6 ++++++ src/lib-storage/index/index-mail.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/lib-storage/index/index-mail-headers.c b/src/lib-storage/index/index-mail-headers.c index 7ce4bfce49..3bc3fd8161 100644 --- a/src/lib-storage/index/index-mail-headers.c +++ b/src/lib-storage/index/index-mail-headers.c @@ -130,6 +130,7 @@ static void index_mail_parse_header_finish(struct index_mail *mail) } mail->data.dont_cache_field_idx = UINT_MAX; + mail->data.header_parser_initialized = FALSE; } static unsigned int @@ -247,6 +248,9 @@ void index_mail_parse_header_init(struct index_mail *mail, array_idx_set(&mail->header_match, field_idx, &mail->header_match_value); } + mail->data.header_parser_initialized = TRUE; + mail->data.parse_line_num = 0; + memset(&mail->data.parse_line, 0, sizeof(mail->data.parse_line)); } static void index_mail_parse_finish_imap_envelope(struct index_mail *mail) @@ -276,6 +280,8 @@ void index_mail_parse_header(struct message_part *part, unsigned int field_idx, count; uint8_t *match; + i_assert(data->header_parser_initialized); + data->parse_line_num++; if (data->save_bodystructure_header) { diff --git a/src/lib-storage/index/index-mail.h b/src/lib-storage/index/index-mail.h index 5842c4c5ec..298a46d1a2 100644 --- a/src/lib-storage/index/index-mail.h +++ b/src/lib-storage/index/index-mail.h @@ -126,6 +126,7 @@ struct index_mail_data { unsigned int initialized_wrapper_stream:1; unsigned int destroy_callback_set:1; unsigned int prefetch_sent:1; + unsigned int header_parser_initialized:1; }; struct index_mail { -- 2.47.3