From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Subject: [PATCH] Fix CVE-2026-52681 Upstream commits: lib-storage: Allow NULL path in mailbox_list_mkdir_root() https://github.com/dovecot/core/commit/a56d0685ef2e3369b4fdce14e59a2c3dfec8f44e lib-storage: Simplify mailbox_mkdir() using mailbox_list_mkdir_root(NULL) https://github.com/dovecot/core/commit/9276a4f55e0ea38c735cf386fa5578891f51b99c Taken from the Debian bookworm security update (dovecot 1:2.3.19.1+dfsg1-2.1+deb12u7), which carries these fixes for 2.3, and applied to 2.3.21.1. The Pigeonhole part of this fix is in mail/pigeonhole/patches. --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -3025,12 +3025,10 @@ int mailbox_mkdir(struct mailbox *box, c enum mailbox_list_path_type type) { const struct mailbox_permissions *perm = mailbox_get_permissions(box); - const char *root_dir; if (!perm->gid_origin_is_mailbox_path) { /* mailbox root directory doesn't exist, create it */ - root_dir = mailbox_list_get_root_forced(box->list, type); - if (mailbox_list_mkdir_root(box->list, root_dir, type) < 0) { + if (mailbox_list_mkdir_root(box->list, NULL, type) < 0) { mail_storage_copy_list_error(box->storage, box->list); return -1; } --- a/src/lib-storage/mailbox-list.c +++ b/src/lib-storage/mailbox-list.c @@ -1272,6 +1272,10 @@ int mailbox_list_mkdir_root(struct mailb { const char *error; + if (path == NULL && + !mailbox_list_get_root_path(list, type, &path)) + return 0; + if (mailbox_list_try_mkdir_root(list, path, type, &error) < 0) { mailbox_list_set_critical(list, "%s", error); return -1; --- a/src/lib-storage/mailbox-list.h +++ b/src/lib-storage/mailbox-list.h @@ -238,7 +238,9 @@ void mailbox_list_get_permissions(struct void mailbox_list_get_root_permissions(struct mailbox_list *list, struct mailbox_permissions *permissions_r); /* mkdir() a root directory of given type with proper permissions. The path can - be either the root itself or point to a directory under the root. */ + be either the root itself or point to a directory under the root. If path is + NULL, the root path of the given type is looked up automatically; if there is + no such path, nothing is done. */ int mailbox_list_mkdir_root(struct mailbox_list *list, const char *path, enum mailbox_list_path_type type); /* Like mailbox_list_mkdir_root(), but don't log an error if it fails. */