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

Commit 9027c0f

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 <vieuxtech@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e13e8fe commit 9027c0f

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

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);
@@ -2355,12 +2363,11 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) {
23552363
size_t len = Buffer::Length(obj);
23562364

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

23622369
if (!SSL_set_tlsext_status_ocsp_resp(s, data, len))
2363-
allocator->Free(data, len);
2370+
OPENSSL_free(data);
23642371
w->ocsp_response_.Reset();
23652372

23662373
return SSL_TLSEXT_ERR_OK;

0 commit comments

Comments
 (0)