]> 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)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 11 Nov 2026 12:17:01 +0000 (16:17 +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 1b077a469305b575c85fd80f133460d52bbbb75d..19e4caf1320e824d88dde10e54f9cc86c3188dbd 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;