diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index e805a984322c83..2e571fc6ba5564 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -86,8 +86,15 @@ MaybeLocal ToV8Value( Environment* env, const BIOPointer& bio, const EVPKeyPointer::AsymmetricKeyEncodingConfig& config) { - if (!bio) return {}; + if (!bio) { + THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Invalid BIO pointer"); + return {}; + } BUF_MEM* bptr = bio; + if (!bptr) { + THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Unable to create BUF_MEM pointer"); + return {}; + } if (config.format == EVPKeyPointer::PKFormatType::PEM) { // PEM is an ASCII format, so we will return it as a string. return String::NewFromUtf8( diff --git a/src/crypto/crypto_x509.cc b/src/crypto/crypto_x509.cc index f40f6dd4f2bcaf..6ac4dd2adb38b6 100644 --- a/src/crypto/crypto_x509.cc +++ b/src/crypto/crypto_x509.cc @@ -106,6 +106,8 @@ MaybeLocal ToV8Value(Local context, BIOPointer&& bio) { if (!bio) [[unlikely]] return {}; BUF_MEM* mem = bio; + if (!mem) [[unlikely]] + return {}; Local ret; if (!String::NewFromUtf8(Isolate::GetCurrent(), mem->data, @@ -120,6 +122,8 @@ MaybeLocal ToV8Value(Local context, const BIOPointer& bio) { if (!bio) [[unlikely]] return {}; BUF_MEM* mem = bio; + if (!mem) [[unlikely]] + return {}; Local ret; if (!String::NewFromUtf8(Isolate::GetCurrent(), mem->data, @@ -134,6 +138,8 @@ MaybeLocal ToBuffer(Environment* env, BIOPointer* bio) { if (bio == nullptr || !*bio) [[unlikely]] return {}; BUF_MEM* mem = *bio; + if (!mem) [[unlikely]] + return {}; #ifdef V8_ENABLE_SANDBOX // If the v8 sandbox is enabled, then all array buffers must be allocated // via the isolate. External buffers are not allowed. So, instead of wrapping