Skip to content

Commit 7778ebe

Browse files
addaleaxtargos
authored andcommitted
src: turn SSL_CTX_new CHECK/segfault into JS exception
These operations do not usually fail, but can do so when OpenSSL is not configured properly (I ran into this while dynamically linking against OpenSSL with FIPS). JS exceptions are way more useful than CHECK failures or plain segfaults. PR-URL: #42799 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b69396a commit 7778ebe

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/crypto/crypto_cipher.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,14 @@ void CipherBase::GetSSLCiphers(const FunctionCallbackInfo<Value>& args) {
198198
Environment* env = Environment::GetCurrent(args);
199199

200200
SSLCtxPointer ctx(SSL_CTX_new(TLS_method()));
201-
CHECK(ctx);
201+
if (!ctx) {
202+
return ThrowCryptoError(env, ERR_get_error(), "SSL_CTX_new");
203+
}
202204

203205
SSLPointer ssl(SSL_new(ctx.get()));
204-
CHECK(ssl);
206+
if (!ssl) {
207+
return ThrowCryptoError(env, ERR_get_error(), "SSL_new");
208+
}
205209

206210
STACK_OF(SSL_CIPHER)* ciphers = SSL_get_ciphers(ssl.get());
207211

src/crypto/crypto_context.cc

+3
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
508508
}
509509

510510
sc->ctx_.reset(SSL_CTX_new(method));
511+
if (!sc->ctx_) {
512+
return ThrowCryptoError(env, ERR_get_error(), "SSL_CTX_new");
513+
}
511514
SSL_CTX_set_app_data(sc->ctx_.get(), sc);
512515

513516
// Disable SSLv2 in the case when method == TLS_method() and the

0 commit comments

Comments
 (0)