From: Timo Sirainen Date: Fri, 24 Feb 2023 14:22:28 +0000 (+0200) Subject: doveadm: Panic if doveadm_print_init() is called too late X-Git-Tag: 2.4.0~2943 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f26ccc8298ef9ee7cf4647ae4772cd8c4f956ee0;p=thirdparty%2Fdovecot%2Fcore.git doveadm: Panic if doveadm_print_init() is called too late Otherwise it's not noticed unless the doveadm command is called for multiple users (-A, -F). --- diff --git a/src/doveadm/doveadm-mail.c b/src/doveadm/doveadm-mail.c index 42fcc00b58..82a07012f4 100644 --- a/src/doveadm/doveadm-mail.c +++ b/src/doveadm/doveadm-mail.c @@ -626,6 +626,11 @@ doveadm_mail_cmd_init(const struct doveadm_mail_cmd *cmd, ctx->v.get_next_user = doveadm_mail_cmd_get_next_user; if (ctx->v.deinit == NULL) ctx->v.deinit = doveadm_mail_cmd_deinit_noop; + if (!doveadm_print_is_initialized()) { + /* alloc() should call doveadm_print_init(). It's too late + afterwards. */ + doveadm_print_init_disallow(TRUE); + } p_array_init(&ctx->module_contexts, ctx->pool, 5); return ctx; diff --git a/src/doveadm/doveadm-print.c b/src/doveadm/doveadm-print.c index 5feb3c9be1..70e9ae11d2 100644 --- a/src/doveadm/doveadm-print.c +++ b/src/doveadm/doveadm-print.c @@ -25,6 +25,7 @@ bool doveadm_print_hide_titles = FALSE; struct ostream *doveadm_print_ostream = NULL; static struct doveadm_print_context *ctx; +static bool doveadm_print_init_disallowed = FALSE; bool doveadm_print_is_initialized(void) { @@ -163,6 +164,8 @@ void doveadm_print_init(const char *name) /* already forced the type */ return; } + if (doveadm_print_init_disallowed) + i_panic("doveadm_print_init() is called in wrong place"); pool = pool_alloconly_create("doveadm print", 1024); ctx = p_new(pool, struct doveadm_print_context, 1); @@ -198,4 +201,11 @@ void doveadm_print_deinit(void) i_free(hdr->sticky_value); pool_unref(&ctx->pool); ctx = NULL; + + doveadm_print_init_disallowed = FALSE; +} + +void doveadm_print_init_disallow(bool disallow) +{ + doveadm_print_init_disallowed = disallow; } diff --git a/src/doveadm/doveadm-print.h b/src/doveadm/doveadm-print.h index a907d9038d..7edbe73c0d 100644 --- a/src/doveadm/doveadm-print.h +++ b/src/doveadm/doveadm-print.h @@ -44,6 +44,9 @@ void doveadm_print_flush(void); void doveadm_print_init(const char *name); void doveadm_print_deinit(void); +/* Panic if doveadm_print_init() is attempted to be called. This is reset also + by doveadm_print_deinit(). */ +void doveadm_print_init_disallow(bool disallow); void doveadm_print_formatted_set_format(const char *format);