From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Subject: [PATCH] Fix CVE-2026-42395 Upstream commits: submission-login: Fix parsing multiple XCLIENT FORWARD parameters https://github.com/dovecot/core/commit/a1ce604684d5920001a2768dacc00ab00050c8af pop3/submission-login: Split off a common client_forward_decode_base64() https://github.com/dovecot/core/commit/ac69e4c3351f8e65e8af18a3befe40a7844aa0e6 login-common: Fix crash when XCLIENT FORWARD= base64 contains NUL byte https://github.com/dovecot/core/commit/7fc304a8109fe484ab4026b4cfbe39ce82351319 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. --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -745,6 +745,23 @@ void client_add_forward_field(struct cli str_append_tabescaped(client->forward_fields, value); } +bool client_forward_decode_base64(struct client *client, const char *value) +{ + size_t value_len = strlen(value); + string_t *str = str_new(client->preproxy_pool, + MAX_BASE64_DECODED_SIZE(value_len)); + if (base64_decode(value, value_len, NULL, str) < 0) + return FALSE; + /* Embedded NUL would yield a created-but-empty array, panicking later + in array_front() during sasl_server_auth_begin(). */ + if (str_len(str) == 0 || + memchr(str_data(str), '\0', str_len(str)) != NULL) + return FALSE; + + client->forward_fields = str; + return TRUE; +} + const char *client_get_session_id(struct client *client) { buffer_t *buf, *base64_buf; --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -319,6 +319,7 @@ struct client *clients_get_first_fd_prox void client_add_forward_field(struct client *client, const char *key, const char *value); +bool client_forward_decode_base64(struct client *client, const char *value); void client_set_title(struct client *client); const char *client_get_extra_disconnect_reason(struct client *client); --- a/src/pop3-login/client.c +++ b/src/pop3-login/client.c @@ -68,12 +68,7 @@ static bool cmd_xclient(struct pop3_clie if (str_to_uint(*tmp + 4, &client->common.proxy_ttl) < 0) args_ok = FALSE; } else if (strncasecmp(*tmp, "FORWARD=", 8) == 0) { - size_t value_len = strlen((*tmp)+8); - client->common.forward_fields = - str_new(client->common.preproxy_pool, - MAX_BASE64_DECODED_SIZE(value_len)); - if (base64_decode((*tmp)+8, value_len, NULL, - client->common.forward_fields) < 0) + if (!client_forward_decode_base64(&client->common, (*tmp)+8)) args_ok = FALSE; } } --- a/src/submission-login/client.c +++ b/src/submission-login/client.c @@ -193,18 +193,9 @@ client_connection_cmd_xclient(void *cont const char *value = data->extra_fields[i].value; if (strcasecmp(name, "FORWARD") == 0) { - size_t value_len = strlen(value); - if (client->common.forward_fields != NULL) { - str_truncate(client->common.forward_fields, 0); - } else { - client->common.forward_fields = str_new( - client->common.preproxy_pool, - MAX_BASE64_DECODED_SIZE(value_len)); - if (base64_decode(value, value_len, NULL, - client->common.forward_fields) < 0) { - smtp_server_reply(cmd, 501, "5.5.4", - "Invalid FORWARD parameter"); - } + if (!client_forward_decode_base64(&client->common, value)) { + smtp_server_reply(cmd, 501, "5.5.4", + "Invalid FORWARD parameter"); } } }