dovecot-2.0: mbox: Avoid crashing when getting GUID or header-md...

dovecot at dovecot.org dovecot at dovecot.org
Tue Aug 23 22:14:53 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/030394c74f54
changeset: 12882:030394c74f54
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Aug 23 22:14:38 2011 +0300
description:
mbox: Avoid crashing when getting GUID or header-md5 in some conditions.
mbox file can be opened and locked (especially with pop3_lock_session=yes)
without actually creating a stream for it.

diffstat:

 src/lib-storage/index/mbox/mbox-mail.c |  13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diffs (34 lines):

diff -r 35e4a547231c -r 030394c74f54 src/lib-storage/index/mbox/mbox-mail.c
--- a/src/lib-storage/index/mbox/mbox-mail.c	Tue Aug 23 21:41:24 2011 +0300
+++ b/src/lib-storage/index/mbox/mbox-mail.c	Tue Aug 23 22:14:38 2011 +0300
@@ -179,6 +179,7 @@
 	struct index_mail *mail = (struct index_mail *)_mail;
 	struct mbox_mailbox *mbox = (struct mbox_mailbox *)_mail->box;
 	uoff_t offset;
+	bool move_offset;
 
 	switch (field) {
 	case MAIL_FETCH_FROM_ENVELOPE:
@@ -195,13 +196,19 @@
 		/* i guess in theory the empty_md5 is valid and can happen,
 		   but it's almost guaranteed that it means the MD5 sum is
 		   missing. recalculate it. */
-		offset = mbox->mbox_lock_type == F_UNLCK ? 0 :
-			istream_raw_mbox_get_start_offset(mbox->mbox_stream);
+		if (mbox->mbox_lock_type == F_UNLCK ||
+		    mbox->mbox_stream == NULL) {
+			offset = 0;
+			move_offset = FALSE;
+		} else {
+			offset = istream_raw_mbox_get_start_offset(mbox->mbox_stream);
+			move_offset = TRUE;
+		}
 		mbox->mbox_save_md5 = TRUE;
 		if (mbox_sync(mbox, MBOX_SYNC_FORCE_SYNC |
 			      MBOX_SYNC_READONLY) < 0)
 			return -1;
-		if (mbox->mbox_lock_type != F_UNLCK) {
+		if (move_offset) {
 			if (istream_raw_mbox_seek(mbox->mbox_stream,
 						  offset) < 0) {
 				i_error("mbox %s sync lost during MD5 syncing",


More information about the dovecot-cvs mailing list