]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Make sure rebuilding doesn't try to add a copy of the message too many times.
authorTimo Sirainen <tss@iki.fi>
Thu, 2 Jul 2015 09:06:04 +0000 (11:06 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 2 Jul 2015 09:06:04 +0000 (11:06 +0200)
Currently it just silently overflowed the 16bit refcount, which caused
problems later.

src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c

index 43090ca05c6e6a2469501d9fc917abdf6ff2eca5..3ccc15b956828da07ed2d1732b24b9f4d985c4ff 100644 (file)
@@ -20,6 +20,8 @@
 #include <dirent.h>
 #include <unistd.h>
 
+#define REBUILD_MAX_REFCOUNT 32768
+
 struct mdbox_rebuild_msg {
        struct mdbox_rebuild_msg *guid_hash_next;
 
@@ -458,7 +460,8 @@ rebuild_mailbox_multi(struct mdbox_storage_rebuild_context *ctx,
                           GUID exists multiple times */
                }
 
-               if (rec != NULL) T_BEGIN {
+               if (rec != NULL &&
+                   rec->refcount < REBUILD_MAX_REFCOUNT) T_BEGIN {
                        /* keep this message. add it to mailbox index. */
                        i_assert(map_uid != 0);
                        rec->refcount++;
@@ -758,6 +761,7 @@ static int rebuild_restore_msg(struct mdbox_storage_rebuild_context *ctx,
        mail_index_update_ext(ctx->prev_msg.trans, seq, mbox->guid_ext_id,
                              msg->guid_128, NULL);
 
+       i_assert(msg->refcount == 0);
        msg->refcount++;
        return 0;
 }