From a32a59874898e2ba3961ba3e11563b6e2d72de98 Mon Sep 17 00:00:00 2001 From: ndossche Date: Thu, 19 Feb 2026 16:46:15 +0100 Subject: [PATCH] crypto: fix missing nullptr check on RSA_new() Not checking this can cause a null deref. Since there is already a null check at the bottom of the function with `NewRSA()`. PR-URL: https://github.com/nodejs/node/pull/61888 Reviewed-By: Anna Henningsen --- src/crypto/crypto_rsa.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc index e7546cec4c1..62ee228945c 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -385,6 +385,11 @@ KeyObjectData ImportJWKRsaKey(Environment* env, KeyType type = d_value->IsString() ? kKeyTypePrivate : kKeyTypePublic; RSAPointer rsa(RSA_new()); + if (!rsa) { + THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Unable to create RSA pointer"); + return {}; + } + ncrypto::Rsa rsa_view(rsa.get()); ByteSource n = ByteSource::FromEncodedString(env, n_value.As()); @@ -435,7 +440,10 @@ KeyObjectData ImportJWKRsaKey(Environment* env, } auto pkey = EVPKeyPointer::NewRSA(std::move(rsa)); - if (!pkey) return {}; + if (!pkey) { + THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Unable to create key pointer"); + return {}; + } return KeyObjectData::CreateAsymmetric(type, std::move(pkey)); }