Skip to content

Commit

Permalink
lib-storage: Prevent renaming mailbox under itself.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen authored and GitLab committed Nov 16, 2016
1 parent bcfeddf commit 606e388
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib-storage/list/mailbox-list-index-backend.c
Expand Up @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit 606e388

Please sign in to comment.