From: Vadim Zhestikov Date: Wed, 4 Nov 2026 17:54:11 +0000 (-0800) Subject: Mail: fixed use-after-free on client reset during auth_http request X-Git-Tag: release-1.31.9~7 X-Git-Url: https://git.kaiwu.me/http/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=754fe68c2e0f698baf731666e71b7f2619c715ef;p=nginx.git Mail: fixed use-after-free on client reset during auth_http request When a client command starts an auth_http request, the default reply set by the POP3, IMAP and SMTP auth state handlers remains in s->out, though it is never used: the actual reply depends on the auth_http response. With ngx_mail_send() as the client write handler, the reply could be sent before the authentication result was known, and if the client reset the connection, the failed send destroyed the session while the auth_http connection still referenced it. The queued reply is now discarded when the auth_http request starts, similarly to ngx_mail_proxy_init(). Reported by Xint.io. --- diff --git a/src/mail/ngx_mail_auth_http_module.c b/src/mail/ngx_mail_auth_http_module.c index 1b077a469..19e4caf13 100644 --- a/src/mail/ngx_mail_auth_http_module.c +++ b/src/mail/ngx_mail_auth_http_module.c @@ -216,6 +216,8 @@ ngx_mail_auth_http_init(ngx_mail_session_t *s) ctx->peer.connection->data = s; ctx->peer.connection->pool = s->connection->pool; + s->out.len = 0; + s->connection->read->handler = ngx_mail_auth_http_block_read; ctx->peer.connection->read->handler = ngx_mail_auth_http_read_handler; ctx->peer.connection->write->handler = ngx_mail_auth_http_write_handler;