From: Sergey Kandaurov Date: Thu, 29 Oct 2026 16:39:27 +0000 (+0400) Subject: Core: fixed segfault in PROXY protocol v2 with dynamic certificates X-Git-Tag: release-1.31.9~2 X-Git-Url: https://git.kaiwu.me/http/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=c4892abca630a345a06a9b7508e13f4600485e10;p=nginx.git Core: fixed segfault in PROXY protocol v2 with dynamic certificates If PROXY protocol v2 was enabled with dynamic certificate loading, notably in the stream module, a segmentation fault might happen. The reason is that during an abbreviated handshake the certificate callback is not called, leading to NULL being returned from SSL_get_certificate(). The fix is similar to 5784889fb. Reported by ruokeqx. --- diff --git a/src/core/ngx_proxy_protocol.c b/src/core/ngx_proxy_protocol.c index d1ff171bc..31e1bd76a 100644 --- a/src/core/ngx_proxy_protocol.c +++ b/src/core/ngx_proxy_protocol.c @@ -954,6 +954,10 @@ ngx_proxy_protocol_v2_ssl_sub(ngx_connection_t *c, ngx_uint_t type, case NGX_PROXY_PROTOCOL_TLV_SSL_SIG_ALG: cert = SSL_get_certificate(c->ssl->connection); + if (cert == NULL) { + return NGX_DECLINED; + } + out->data = (u_char *) OBJ_nid2sn(X509_get_signature_nid(cert)); out->len = ngx_strlen(out->data); return NGX_OK; @@ -961,6 +965,10 @@ ngx_proxy_protocol_v2_ssl_sub(ngx_connection_t *c, ngx_uint_t type, case NGX_PROXY_PROTOCOL_TLV_SSL_KEY_ALG: cert = SSL_get_certificate(c->ssl->connection); + if (cert == NULL) { + return NGX_DECLINED; + } + pkey = X509_get_pubkey(cert); if (pkey == NULL) { return NGX_ERROR;