From: Martti Rannanjärvi Date: Thu, 16 Jun 2022 13:53:47 +0000 (+0300) Subject: mail-crypt: mail_crypt_user_set_private_key() - Move mailbox alloc later to avoid... X-Git-Tag: 2.4.0~3949 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e74e525947a07145601b294b9288306de05c3fd4;p=thirdparty%2Fdovecot%2Fcore.git mail-crypt: mail_crypt_user_set_private_key() - Move mailbox alloc later to avoid a panic This fixes: Panic: file mail-user.c: line 252 (mail_user_deinit): assertion failed: ((*user)->refcount == 1) When mail_crypt_require_encrypted_user_key is enabled and the user does not have key or password. --- diff --git a/src/plugins/mail-crypt/mail-crypt-key.c b/src/plugins/mail-crypt/mail-crypt-key.c index 76e8114c8d..df52cdbb6b 100644 --- a/src/plugins/mail-crypt/mail-crypt-key.c +++ b/src/plugins/mail-crypt/mail-crypt-key.c @@ -466,9 +466,6 @@ int mail_crypt_user_set_private_key(struct mail_user *user, const char *pubid, struct dcrypt_private_key *key, const char **error_r) { - struct mail_namespace *ns = mail_namespace_find_inbox(user->namespaces); - struct mailbox *box = mailbox_alloc(ns->list, "INBOX", - MAILBOX_FLAG_READONLY); struct dcrypt_private_key *env_key = NULL; struct dcrypt_public_key *enc_key = NULL; struct mailbox_transaction_context *t; @@ -494,6 +491,9 @@ int mail_crypt_user_set_private_key(struct mail_user *user, const char *pubid, return -1; } + struct mail_namespace *ns = mail_namespace_find_inbox(user->namespaces); + struct mailbox *box = mailbox_alloc(ns->list, "INBOX", + MAILBOX_FLAG_READONLY); if (mailbox_open(box) < 0) { *error_r = t_strdup_printf("mailbox_open(%s) failed: %s", "INBOX",