From: Timo Sirainen Date: Tue, 30 May 2023 08:10:39 +0000 (+0300) Subject: imap: Fix crash when trying to use COMPRESS multiple times X-Git-Tag: 2.4.0~2725 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9128b0757b2a73dd76aea8cde82a12f82c46cec;p=thirdparty%2Fdovecot%2Fcore.git imap: Fix crash when trying to use COMPRESS multiple times Broken by 5f27e25c64555dcaae6cb00c479cd05bc2638081 Fixes: Panic: file cmd-compress.c: line 104 (cmd_compress): assertion failed: (client->input->v_offset == prev_in_offset) --- diff --git a/src/imap/cmd-compress.c b/src/imap/cmd-compress.c index 00fb36ff48..52c74b5a82 100644 --- a/src/imap/cmd-compress.c +++ b/src/imap/cmd-compress.c @@ -59,6 +59,12 @@ bool cmd_compress(struct client_command_context *cmd) return TRUE; } + if (client->compress_handler != NULL) { + client_send_tagline(cmd, t_strdup_printf( + "NO [COMPRESSIONACTIVE] COMPRESSION=%s already enabled.", + t_str_ucase(client->compress_handler->name))); + return TRUE; + } int ret = compression_lookup_handler(t_str_lcase(mechanism), &handler); if (ret <= 0) { const char * tagline = @@ -121,5 +127,6 @@ bool cmd_compress(struct client_command_context *cmd) } client_update_imap_parser_streams(client); + client->compress_handler = handler; return TRUE; } diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index ad1e6f5c5d..194d7aa059 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -212,6 +212,8 @@ struct client { /* NOTIFY extension */ struct imap_notify_context *notify_ctx; uint32_t notify_uidnext; + /* COMPRESS extension */ + const struct compression_handler *compress_handler; /* client input/output is locked by this command */ struct client_command_context *input_lock;