changeset 22740:2b2c4857a52b

lib-storage: mail_storage_set_index_error() - handle NULL index error This avoids assert-crashing later on in mail*_get_last_internal_error(). This could potentially be an assert instead of setting it as "BUG", but it looks like there are various code paths in lib-index that return -1 without setting an error. (That's to avoid duplicate error logging, although it could now be fixed with mail_index_set_error_nolog().)
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 25 Dec 2017 18:24:35 +0200
parents 833b129bf451
children b09a8c92479b
files src/lib-storage/mail-storage.c
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.c	Mon Dec 25 18:18:14 2017 +0200
+++ b/src/lib-storage/mail-storage.c	Mon Dec 25 18:24:35 2017 +0200
@@ -616,10 +616,14 @@
 void mail_storage_set_index_error(struct mail_storage *storage,
 				  struct mail_index *index)
 {
+	const char *index_error;
+
 	mail_storage_set_internal_error(storage);
 	/* use the lib-index's error as our internal error string */
-	storage->last_internal_error =
-		i_strdup(mail_index_get_error_message(index));
+	index_error = mail_index_get_error_message(index);
+	if (index_error == NULL)
+		index_error = "BUG: Unknown internal index error";
+	storage->last_internal_error = i_strdup(index_error);
 	storage->last_error_is_internal = TRUE;
 	mail_index_reset_error(index);
 }