changeset 21133:17b679988b72

lib-storage: Prevent renaming mailbox under itself. 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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 16 Nov 2016 01:09:57 +0200
parents e3e79ca1689d
children 025a27734fda
files src/lib-storage/list/mailbox-list-index-backend.c
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/list/mailbox-list-index-backend.c	Wed Nov 16 01:04:18 2016 +0200
+++ b/src/lib-storage/list/mailbox-list-index-backend.c	Wed Nov 16 01:09:57 2016 +0200
@@ -582,6 +582,7 @@
 			  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 @@
 		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;