From: Timo Sirainen Date: Thu, 9 Oct 2014 13:42:01 +0000 (+0300) Subject: lib-storage: If uncached header unfolding fails, panic instead of returning error. X-Git-Tag: 2.2.14~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=073f965351846b8c97347b882c441dc336965e26;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: If uncached header unfolding fails, panic instead of returning error. This really shouldn't be happening. This also makes it clear that return value -1 means some kind of I/O error instead of corruption. --- diff --git a/src/lib-storage/index/index-mail-headers.c b/src/lib-storage/index/index-mail-headers.c index 986949bfd3..47f883304e 100644 --- a/src/lib-storage/index/index-mail-headers.c +++ b/src/lib-storage/index/index-mail-headers.c @@ -773,9 +773,10 @@ int index_mail_get_headers(struct mail *_mail, const char *field, bool decode_to_utf8, const char *const **value_r) { struct index_mail *mail = (struct index_mail *)_mail; - int ret, i; + bool retry = TRUE; + int ret; - for (i = 0; i < 2; i++) { + for (;; retry = FALSE) { if (index_mail_get_raw_headers(mail, field, value_r) < 0) return -1; if (!decode_to_utf8 || **value_r == NULL) @@ -785,16 +786,20 @@ int index_mail_get_headers(struct mail *_mail, const char *field, ret = index_mail_headers_decode(mail, value_r, UINT_MAX); } T_END; - if (ret < 0) { + if (ret < 0 && retry) { mail_cache_set_corrupted(_mail->box->cache, "Broken header %s for mail UID %u", field, _mail->uid); - /* retry by parsing the full header */ } else { break; } } - return ret; + if (ret < 0) { + i_panic("BUG: Broken header %s for mail UID %u " + "wasn't fixed by re-parsing the header", + field, _mail->uid); + } + return 1; } int index_mail_get_first_header(struct mail *_mail, const char *field, @@ -802,9 +807,10 @@ int index_mail_get_first_header(struct mail *_mail, const char *field, { struct index_mail *mail = (struct index_mail *)_mail; const char *const *list; - int ret, i; + bool retry = TRUE; + int ret; - for (i = 0; i < 2; i++) { + for (;; retry = FALSE) { if (index_mail_get_raw_headers(mail, field, &list) < 0) return -1; if (!decode_to_utf8 || list[0] == NULL) { @@ -816,7 +822,7 @@ int index_mail_get_first_header(struct mail *_mail, const char *field, ret = index_mail_headers_decode(mail, &list, 1); } T_END; - if (ret < 0) { + if (ret < 0 && retry) { mail_cache_set_corrupted(_mail->box->cache, "Broken header %s for mail UID %u", field, _mail->uid); @@ -825,8 +831,13 @@ int index_mail_get_first_header(struct mail *_mail, const char *field, break; } } + if (ret < 0) { + i_panic("BUG: Broken header %s for mail UID %u " + "wasn't fixed by re-parsing the header", + field, _mail->uid); + } *value_r = list[0]; - return ret < 0 ? -1 : (list[0] != NULL ? 1 : 0); + return list[0] != NULL ? 1 : 0; } static void