From: Timo Sirainen Date: Thu, 23 Sep 2010 17:18:51 +0000 (+0100) Subject: maildir: Fixed a race condition in getting a new message's GUID. X-Git-Tag: 2.0.4~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=24cd47a2c8f7507e555459b7e841de771ba3c318;p=thirdparty%2Fdovecot%2Fcore.git maildir: Fixed a race condition in getting a new message's GUID. --- diff --git a/src/lib-storage/index/maildir/maildir-mail.c b/src/lib-storage/index/maildir/maildir-mail.c index 366774c0bf..8742cc3102 100644 --- a/src/lib-storage/index/maildir/maildir-mail.c +++ b/src/lib-storage/index/maildir/maildir-mail.c @@ -469,11 +469,17 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field, { struct index_mail *mail = (struct index_mail *)_mail; struct maildir_mailbox *mbox = (struct maildir_mailbox *)_mail->box; - const char *path, *fname, *end, *guid, *uidl; + const char *path, *fname = NULL, *end, *guid, *uidl; switch (field) { case MAIL_FETCH_GUID: /* use GUID from uidlist if it exists */ + i_assert(!_mail->saving); + + /* first make sure that we have a refreshed uidlist */ + if (maildir_mail_get_fname(mbox, _mail, &fname) <= 0) + return -1; + guid = maildir_uidlist_lookup_ext(mbox->uidlist, _mail->uid, MAILDIR_UIDLIST_REC_EXT_GUID); if (guid != NULL) { @@ -487,7 +493,10 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field, *value_r = mail->data.guid; return 0; } - if (!_mail->saving) { + if (fname != NULL) { + /* we came here from MAIL_FETCH_GUID, + avoid a second lookup */ + } else if (!_mail->saving) { if (maildir_mail_get_fname(mbox, _mail, &fname) <= 0) return -1; } else {