dovecot-2.2: lib-storage: If uncached header unfolding fails, pa...

dovecot at dovecot.org dovecot at dovecot.org
Thu Oct 9 13:42:38 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/43f17a91c6e5
changeset: 17918:43f17a91c6e5
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Oct 09 16:42:01 2014 +0300
description:
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.

diffstat:

 src/lib-storage/index/index-mail-headers.c |  29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

diffs (77 lines):

diff -r 0e1a3c909a13 -r 43f17a91c6e5 src/lib-storage/index/index-mail-headers.c
--- a/src/lib-storage/index/index-mail-headers.c	Thu Oct 09 16:41:23 2014 +0300
+++ b/src/lib-storage/index/index-mail-headers.c	Thu Oct 09 16:42:01 2014 +0300
@@ -773,9 +773,10 @@
 			   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 @@
 			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 @@
 {
 	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 @@
 			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 @@
 			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


More information about the dovecot-cvs mailing list