[ruby/openssl] ssl: fix potential memory leak in SSLContext#setup

If SSL_CTX_add_extra_chain_cert() fails, the refcount of x509 must be
handled by the caller. This should only occur due to a malloc failure
inside the function.

https://github.com/ruby/openssl/commit/80bcf727dc
This commit is contained in:
Kazuki Yamaguchi 2025-04-20 16:22:01 +09:00 committed by git
parent b43c7cf8c4
commit 06a56a7ffc

View File

@ -430,8 +430,9 @@ ossl_sslctx_add_extra_chain_cert_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
GetSSLCTX(arg, ctx);
x509 = DupX509CertPtr(i);
if(!SSL_CTX_add_extra_chain_cert(ctx, x509)){
ossl_raise(eSSLError, NULL);
if (!SSL_CTX_add_extra_chain_cert(ctx, x509)) {
X509_free(x509);
ossl_raise(eSSLError, "SSL_CTX_add_extra_chain_cert");
}
return i;