Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 5efd0aa

Browse files
davidbendeepak1556
authored andcommitted
tls: fix malloc mismatch in SSL_set_tlsext_status_ocsp_resp call
SSL_set_tlsext_status_ocsp_resp expects the data to be allocated with OPENSSL_malloc, not libc malloc, so use OpenSSLMalloc. Additionally, though OpenSSL doesn't type-check due to it being a macro, the function is documented to take an unsigned char pointer: https://www.openssl.org/docs/man1.1.0/ssl/SSL_set_tlsext_status_ocsp_resp.html (By default, OPENSSL_malloc is the same as libc malloc, but it is possible to customize this.) PR-URL: nodejs/node#25706 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7461804 commit 5efd0aa

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/node_crypto.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,14 @@ bool EntropySource(unsigned char* buffer, size_t length) {
323323
}
324324

325325

326+
template <typename T>
327+
static T* MallocOpenSSL(size_t count) {
328+
void* mem = OPENSSL_malloc(MultiplyWithOverflowCheck(count, sizeof(T)));
329+
CHECK_IMPLIES(mem == nullptr, count == 0);
330+
return static_cast<T*>(mem);
331+
}
332+
333+
326334
void SecureContext::Initialize(Environment* env, Local<Object> target) {
327335
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
328336
t->InstanceTemplate()->SetInternalFieldCount(1);
@@ -2356,12 +2364,11 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) {
23562364
size_t len = Buffer::Length(obj);
23572365

23582366
// OpenSSL takes control of the pointer after accepting it
2359-
auto* allocator = env->isolate()->GetArrayBufferAllocator();
2360-
uint8_t* data = static_cast<uint8_t*>(allocator->AllocateUninitialized(len));
2367+
unsigned char* data = MallocOpenSSL<unsigned char>(len);
23612368
memcpy(data, resp, len);
23622369

23632370
if (!SSL_set_tlsext_status_ocsp_resp(s, data, len))
2364-
allocator->Free(data, len);
2371+
OPENSSL_free(data);
23652372
w->ocsp_response_.Reset();
23662373

23672374
return SSL_TLSEXT_ERR_OK;

0 commit comments

Comments
 (0)