From 1e245ab5806f76a3d74c2eaa6d73877b64c0296c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 7 Mar 2022 22:28:42 +0100 Subject: [PATCH] crypto: add CHECKs to remaining BIO_s_mem allocs PR-URL: https://github.com/nodejs/node/pull/42155 Reviewed-By: Darshan Sen --- src/crypto/crypto_keys.cc | 2 ++ src/crypto/crypto_x509.cc | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index 08b95190698334..441f5736ec8a70 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -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; @@ -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; diff --git a/src/crypto/crypto_x509.cc b/src/crypto/crypto_x509.cc index 7c299620dfeeb9..398b1a85795431 100644 --- a/src/crypto/crypto_x509.cc +++ b/src/crypto/crypto_x509.cc @@ -196,6 +196,7 @@ void X509Certificate::Subject(const FunctionCallbackInfo& args) { X509Certificate* cert; ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); BIOPointer bio(BIO_new(BIO_s_mem())); + CHECK(bio); Local ret; if (GetSubject(env, bio, cert->get()).ToLocal(&ret)) args.GetReturnValue().Set(ret); @@ -206,6 +207,7 @@ void X509Certificate::Issuer(const FunctionCallbackInfo& args) { X509Certificate* cert; ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); BIOPointer bio(BIO_new(BIO_s_mem())); + CHECK(bio); Local ret; if (GetIssuerString(env, bio, cert->get()).ToLocal(&ret)) args.GetReturnValue().Set(ret); @@ -216,6 +218,7 @@ void X509Certificate::SubjectAltName(const FunctionCallbackInfo& args) { X509Certificate* cert; ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); BIOPointer bio(BIO_new(BIO_s_mem())); + CHECK(bio); Local ret; if (GetSubjectAltNameString(env, bio, cert->get()).ToLocal(&ret)) args.GetReturnValue().Set(ret); @@ -226,6 +229,7 @@ void X509Certificate::InfoAccess(const FunctionCallbackInfo& args) { X509Certificate* cert; ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); BIOPointer bio(BIO_new(BIO_s_mem())); + CHECK(bio); Local ret; if (GetInfoAccessString(env, bio, cert->get()).ToLocal(&ret)) args.GetReturnValue().Set(ret); @@ -236,6 +240,7 @@ void X509Certificate::ValidFrom(const FunctionCallbackInfo& args) { X509Certificate* cert; ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); BIOPointer bio(BIO_new(BIO_s_mem())); + CHECK(bio); Local ret; if (GetValidFrom(env, cert->get(), bio).ToLocal(&ret)) args.GetReturnValue().Set(ret); @@ -246,6 +251,7 @@ void X509Certificate::ValidTo(const FunctionCallbackInfo& args) { X509Certificate* cert; ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder()); BIOPointer bio(BIO_new(BIO_s_mem())); + CHECK(bio); Local ret; if (GetValidTo(env, cert->get(), bio).ToLocal(&ret)) args.GetReturnValue().Set(ret); @@ -325,6 +331,7 @@ void X509Certificate::Pem(const FunctionCallbackInfo& 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)); }