Skip to content

Commit

Permalink
src: improve error handling in CloneSSLCerts
Browse files Browse the repository at this point in the history
If sk_X509_new() returns NULL or if sk_X509_push() fails, return instead
of silently ignoring the error.
  • Loading branch information
tniessen committed Aug 30, 2022
1 parent a5d27f4 commit 936ccbe
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/crypto/crypto_common.cc
Expand Up @@ -323,8 +323,9 @@ constexpr auto GetCipherVersion = GetCipherValue<SSL_CIPHER_get_version>;
StackOfX509 CloneSSLCerts(X509Pointer&& cert,
const STACK_OF(X509)* const ssl_certs) {
StackOfX509 peer_certs(sk_X509_new(nullptr));
if (cert)
sk_X509_push(peer_certs.get(), cert.release());
if (!peer_certs) return StackOfX509();
if (cert && !sk_X509_push(peer_certs.get(), cert.release()))
return StackOfX509();
for (int i = 0; i < sk_X509_num(ssl_certs); i++) {
X509Pointer cert(X509_dup(sk_X509_value(ssl_certs, i)));
if (!cert || !sk_X509_push(peer_certs.get(), cert.get()))
Expand Down

0 comments on commit 936ccbe

Please sign in to comment.