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.

PR-URL: #44410
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
  • Loading branch information
tniessen authored and juanarbol committed Oct 11, 2022
1 parent cae9c5d commit d76e7e4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/crypto/crypto_common.cc
Expand Up @@ -339,8 +339,9 @@ MaybeLocal<Value> GetCipherVersion(Environment* env, const SSL_CIPHER* cipher) {
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 d76e7e4

Please sign in to comment.