Skip to content

Commit a32a598

Browse files
ndosscheaduh95
authored andcommitted
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: #61888 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent fce2930 commit a32a598

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/crypto/crypto_rsa.cc

Lines changed: 9 additions & 1 deletion
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
}

0 commit comments

Comments
 (0)