]> git.kaiwu.me - nginx.git/commitdiff
Core: fixed segfault in PROXY protocol v2 with dynamic certificates
authorSergey Kandaurov <pluknet@nginx.com>
Thu, 29 Oct 2026 16:39:27 +0000 (20:39 +0400)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 11 Nov 2026 12:17:45 +0000 (16:17 +0400)
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.

src/core/ngx_proxy_protocol.c

index d1ff171bc7376757dfbe55378cc2d55bc9be9fdc..31e1bd76aa6b0f076996c05251a8c072ed26bb79 100644 (file)
@@ -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;