◐ Shell
clean mode source ↗

crypto: fix missing nullptr check on RSA_new() · nodejs/node@a32a598

Original file line numberDiff line numberDiff line change

@@ -385,6 +385,11 @@ KeyObjectData ImportJWKRsaKey(Environment* env,

385385

KeyType type = d_value->IsString() ? kKeyTypePrivate : kKeyTypePublic;

386386
387387

RSAPointer rsa(RSA_new());

388+

if (!rsa) {

389+

THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Unable to create RSA pointer");

390+

return {};

391+

}

392+
388393

ncrypto::Rsa rsa_view(rsa.get());

389394
390395

ByteSource n = ByteSource::FromEncodedString(env, n_value.As<String>());

@@ -435,7 +440,10 @@ KeyObjectData ImportJWKRsaKey(Environment* env,

435440

}

436441
437442

auto pkey = EVPKeyPointer::NewRSA(std::move(rsa));

438-

if (!pkey) return {};

443+

if (!pkey) {

444+

THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Unable to create key pointer");

445+

return {};

446+

}

439447
440448

return KeyObjectData::CreateAsymmetric(type, std::move(pkey));

441449

}