]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Prevent renaming mailbox under itself.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 15 Nov 2016 23:09:57 +0000 (01:09 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 18 Nov 2016 11:45:37 +0000 (13:45 +0200)
This resulted earlier in a loop, which broke the mailbox index.
Note that IMAP already prevented this, so it could only be triggered by
other tools, like doveadm.

src/lib-storage/list/mailbox-list-index-backend.c

index 492924d0530a9e46136b384030bce7566a25434c..a00217c796691e503405e18ebfbf7b5a29b7badd 100644 (file)
@@ -582,6 +582,7 @@ index_list_rename_mailbox(struct mailbox_list *_oldlist, const char *oldname,
                          struct mailbox_list *_newlist, const char *newname)
 {
        struct index_mailbox_list *list = (struct index_mailbox_list *)_oldlist;
+       const unsigned int oldname_len = strlen(oldname);
        struct mailbox_list_index_sync_context *sync_ctx;
        struct mailbox_list_index_record oldrec, newrec;
        struct mailbox_list_index_node *oldnode, *newnode, *child;
@@ -595,6 +596,13 @@ index_list_rename_mailbox(struct mailbox_list *_oldlist, const char *oldname,
                return -1;
        }
 
+       if (strncmp(oldname, newname, oldname_len) == 0 &&
+          newname[oldname_len] == mailbox_list_get_hierarchy_sep(_newlist)) {
+               mailbox_list_set_error(_oldlist, MAIL_ERROR_NOTPOSSIBLE,
+                       "Can't rename mailbox under itself.");
+               return -1;
+       }
+
        if (mailbox_list_index_sync_begin(&list->list, &sync_ctx) < 0)
                return -1;