]> git.kaiwu.me - nginx.git/commitdiff
Mail: fixed use-after-free on client reset during auth_http request
authorVadim Zhestikov <v.zhestikov@f5.com>
Wed, 4 Nov 2026 17:54:11 +0000 (09:54 -0800)
committerSergey Kandaurov <pluknet@nginx.com>
Wed, 11 Nov 2026 18:08:26 +0000 (22:08 +0400)
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.

src/mail/ngx_mail_auth_http_module.c

index 3e5095a2d226b25c50f20acffe652956200d5e76..ba166cdb261dde483070c5cc2a86ec5429af9156 100644 (file)
@@ -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;