diff --git a/src/node_crypto.cc b/src/node_crypto.cc index cdb60f048f3..0c32feb2e10 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -323,6 +323,14 @@ bool EntropySource(unsigned char* buffer, size_t length) { } +template +static T* MallocOpenSSL(size_t count) { + void* mem = OPENSSL_malloc(MultiplyWithOverflowCheck(count, sizeof(T))); + CHECK_IMPLIES(mem == nullptr, count == 0); + return static_cast(mem); +} + + void SecureContext::Initialize(Environment* env, Local target) { Local t = env->NewFunctionTemplate(New); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -2356,12 +2364,11 @@ int SSLWrap::TLSExtStatusCallback(SSL* s, void* arg) { size_t len = Buffer::Length(obj); // OpenSSL takes control of the pointer after accepting it - auto* allocator = env->isolate()->GetArrayBufferAllocator(); - uint8_t* data = static_cast(allocator->AllocateUninitialized(len)); + unsigned char* data = MallocOpenSSL(len); memcpy(data, resp, len); if (!SSL_set_tlsext_status_ocsp_resp(s, data, len)) - allocator->Free(data, len); + OPENSSL_free(data); w->ocsp_response_.Reset(); return SSL_TLSEXT_ERR_OK;