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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
  • Loading branch information
tniessen authored and targos committed Sep 16, 2022
1 parent 5a2e509 commit c4a1a60
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
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 c4a1a60

Please sign in to comment.