From: Timo Sirainen Date: Fri, 24 Feb 2023 14:39:14 +0000 (+0200) Subject: doveadm: Panic if doveadm_print_header() is called too late X-Git-Tag: 2.4.0~2942 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=592b850dc085e12210f3905081a4f221ef38b5a5;p=thirdparty%2Fdovecot%2Fcore.git doveadm: Panic if doveadm_print_header() 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 82a07012f4..e524f378e6 100644 --- a/src/doveadm/doveadm-mail.c +++ b/src/doveadm/doveadm-mail.c @@ -509,6 +509,7 @@ int doveadm_mail_single_user(struct doveadm_mail_cmd_context *ctx, T_BEGIN { ctx->v.init(ctx); } T_END; + doveadm_print_header_disallow(TRUE); if (hook_doveadm_mail_init != NULL) hook_doveadm_mail_init(ctx); @@ -533,6 +534,7 @@ doveadm_mail_all_users(struct doveadm_mail_cmd_context *ctx, T_BEGIN { ctx->v.init(ctx); } T_END; + doveadm_print_header_disallow(TRUE); if (wildcard_user != NULL) { mail_storage_service_all_init_mask(ctx->storage_service, diff --git a/src/doveadm/doveadm-print.c b/src/doveadm/doveadm-print.c index 70e9ae11d2..7cad3265ca 100644 --- a/src/doveadm/doveadm-print.c +++ b/src/doveadm/doveadm-print.c @@ -26,6 +26,7 @@ struct ostream *doveadm_print_ostream = NULL; static struct doveadm_print_context *ctx; static bool doveadm_print_init_disallowed = FALSE; +static bool doveadm_print_header_disallowed = FALSE; bool doveadm_print_is_initialized(void) { @@ -40,6 +41,9 @@ void doveadm_print_header(const char *key, const char *title, i_assert(title != NULL); + if (doveadm_print_header_disallowed) + i_panic("doveadm_print_header() is called in wrong place"); + i_zero(&hdr); hdr.key = key; hdr.title = title; @@ -203,9 +207,15 @@ void doveadm_print_deinit(void) ctx = NULL; doveadm_print_init_disallowed = FALSE; + doveadm_print_header_disallowed = FALSE; } void doveadm_print_init_disallow(bool disallow) { doveadm_print_init_disallowed = disallow; } + +void doveadm_print_header_disallow(bool disallow) +{ + doveadm_print_header_disallowed = disallow; +} diff --git a/src/doveadm/doveadm-print.h b/src/doveadm/doveadm-print.h index 7edbe73c0d..81509ac70d 100644 --- a/src/doveadm/doveadm-print.h +++ b/src/doveadm/doveadm-print.h @@ -47,6 +47,9 @@ 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); +/* Panic is doveadm_print_header*() is attempted to be called. This is reset + also by doveadm_print_deinit(). */ +void doveadm_print_header_disallow(bool disallow); void doveadm_print_formatted_set_format(const char *format);