From 0c58d70856f26b64f49b116745b8565f100f4237 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 25 Dec 2017 18:24:35 +0200 Subject: [PATCH] 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().) --- src/lib-storage/mail-storage.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index b93935b053..6dca896690 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -616,10 +616,14 @@ void mailbox_set_index_error(struct mailbox *box) 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); } -- 2.47.3