Skip to content

Commit

Permalink
crypto: add CHECKs to remaining BIO_s_mem allocs
Browse files Browse the repository at this point in the history
PR-URL: #42155
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
tniessen authored Mar 7, 2022
1 parent 14f60fb commit 9440429
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,7 @@ WebCryptoKeyExportStatus PKEY_SPKI_Export(
ManagedEVPPKey m_pkey = key_data->GetAsymmetricKey();
Mutex::ScopedLock lock(*m_pkey.mutex());
BIOPointer bio(BIO_new(BIO_s_mem()));
CHECK(bio);
if (!i2d_PUBKEY_bio(bio.get(), m_pkey.get()))
return WebCryptoKeyExportStatus::FAILED;

Expand All @@ -1439,6 +1440,7 @@ WebCryptoKeyExportStatus PKEY_PKCS8_Export(
Mutex::ScopedLock lock(*m_pkey.mutex());

BIOPointer bio(BIO_new(BIO_s_mem()));
CHECK(bio);
PKCS8Pointer p8inf(EVP_PKEY2PKCS8(m_pkey.get()));
if (!i2d_PKCS8_PRIV_KEY_INFO_bio(bio.get(), p8inf.get()))
return WebCryptoKeyExportStatus::FAILED;
Expand Down
7 changes: 7 additions & 0 deletions src/crypto/crypto_x509.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ void X509Certificate::Subject(const FunctionCallbackInfo<Value>& args) {
X509Certificate* cert;
ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder());
BIOPointer bio(BIO_new(BIO_s_mem()));
CHECK(bio);
Local<Value> ret;
if (GetSubject(env, bio, cert->get()).ToLocal(&ret))
args.GetReturnValue().Set(ret);
Expand All @@ -206,6 +207,7 @@ void X509Certificate::Issuer(const FunctionCallbackInfo<Value>& args) {
X509Certificate* cert;
ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder());
BIOPointer bio(BIO_new(BIO_s_mem()));
CHECK(bio);
Local<Value> ret;
if (GetIssuerString(env, bio, cert->get()).ToLocal(&ret))
args.GetReturnValue().Set(ret);
Expand All @@ -216,6 +218,7 @@ void X509Certificate::SubjectAltName(const FunctionCallbackInfo<Value>& args) {
X509Certificate* cert;
ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder());
BIOPointer bio(BIO_new(BIO_s_mem()));
CHECK(bio);
Local<Value> ret;
if (GetSubjectAltNameString(env, bio, cert->get()).ToLocal(&ret))
args.GetReturnValue().Set(ret);
Expand All @@ -226,6 +229,7 @@ void X509Certificate::InfoAccess(const FunctionCallbackInfo<Value>& args) {
X509Certificate* cert;
ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder());
BIOPointer bio(BIO_new(BIO_s_mem()));
CHECK(bio);
Local<Value> ret;
if (GetInfoAccessString(env, bio, cert->get()).ToLocal(&ret))
args.GetReturnValue().Set(ret);
Expand All @@ -236,6 +240,7 @@ void X509Certificate::ValidFrom(const FunctionCallbackInfo<Value>& args) {
X509Certificate* cert;
ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder());
BIOPointer bio(BIO_new(BIO_s_mem()));
CHECK(bio);
Local<Value> ret;
if (GetValidFrom(env, cert->get(), bio).ToLocal(&ret))
args.GetReturnValue().Set(ret);
Expand All @@ -246,6 +251,7 @@ void X509Certificate::ValidTo(const FunctionCallbackInfo<Value>& args) {
X509Certificate* cert;
ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder());
BIOPointer bio(BIO_new(BIO_s_mem()));
CHECK(bio);
Local<Value> ret;
if (GetValidTo(env, cert->get(), bio).ToLocal(&ret))
args.GetReturnValue().Set(ret);
Expand Down Expand Up @@ -325,6 +331,7 @@ void X509Certificate::Pem(const FunctionCallbackInfo<Value>& args) {
X509Certificate* cert;
ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder());
BIOPointer bio(BIO_new(BIO_s_mem()));
CHECK(bio);
if (PEM_write_bio_X509(bio.get(), cert->get()))
args.GetReturnValue().Set(ToV8Value(env, bio));
}
Expand Down

0 comments on commit 9440429

Please sign in to comment.