BUG/MINOR: ssl: Fix memory leak of find_chain in ssl_sock_load_cert_chain
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Thu, 15 Dec 2022 14:44:37 +0000 (15:44 +0100)
committerWilliam Lallemand <wlallemand@haproxy.org>
Thu, 15 Dec 2022 15:33:43 +0000 (16:33 +0100)
commit4cf0d3f1e8e2ffc6901dc36644efa31b67d172f1
treef768beb07c38b244f652273657512e9e5a711b86
parente3d5f9a92b5c1f0affac677f7ef9b8f030dbb64b
BUG/MINOR: ssl: Fix memory leak of find_chain in ssl_sock_load_cert_chain

The certificate chain that gets passed in the SSL_CTX through
SSL_CTX_set1_chain has its reference counter increased by OpenSSL
itself. But since the ssl_sock_load_cert_chain function might create a
brand new certificate chain if none exists in the ckch_data
(sk_X509_new_null), then we ended up returning a new certificate chain
to the caller that was never destroyed.

This patch can be backported to all stable branches but it might need to
be reworked for branches older than 2.4 because of commit ec805a32b9
that refactorized the modified code.
src/ssl_sock.c