summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@google.com>2019-01-25 04:34:38 +0000
committerAnto Aravinth <anto.aravinth.cse@gmail.com>2019-01-29 21:40:34 +0530
commitb5304662ed23e81948f33d110bb15fc4f3a72cb1 (patch)
treeb2fd721c7c89e8888c83d7639f9adfc50d255ed8 /src
parentc3fd50463f2d3b6be54ebf8b4dbb85157bc08c3f (diff)
downloadandroid-node-v8-b5304662ed23e81948f33d110bb15fc4f3a72cb1.tar.gz
android-node-v8-b5304662ed23e81948f33d110bb15fc4f3a72cb1.tar.bz2
android-node-v8-b5304662ed23e81948f33d110bb15fc4f3a72cb1.zip
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src')
-rw-r--r--src/node_crypto.cc19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 0b6c6c8582..270f74153a 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -326,6 +326,14 @@ bool EntropySource(unsigned char* buffer, size_t length) {
}
+template <typename T>
+static T* MallocOpenSSL(size_t count) {
+ void* mem = OPENSSL_malloc(MultiplyWithOverflowCheck(count, sizeof(T)));
+ CHECK_IMPLIES(mem == nullptr, count == 0);
+ return static_cast<T*>(mem);
+}
+
+
void SecureContext::Initialize(Environment* env, Local<Object> target) {
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
t->InstanceTemplate()->SetInternalFieldCount(1);
@@ -2473,11 +2481,11 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) {
size_t len = Buffer::Length(obj);
// OpenSSL takes control of the pointer after accepting it
- char* data = node::Malloc(len);
+ unsigned char* data = MallocOpenSSL<unsigned char>(len);
memcpy(data, resp, len);
if (!SSL_set_tlsext_status_ocsp_resp(s, data, len))
- free(data);
+ OPENSSL_free(data);
w->ocsp_response_.Reset();
return SSL_TLSEXT_ERR_OK;
@@ -2699,13 +2707,6 @@ static bool IsSupportedAuthenticatedMode(const EVP_CIPHER_CTX* ctx) {
return IsSupportedAuthenticatedMode(cipher);
}
-template <typename T>
-static T* MallocOpenSSL(size_t count) {
- void* mem = OPENSSL_malloc(MultiplyWithOverflowCheck(count, sizeof(T)));
- CHECK_IMPLIES(mem == nullptr, count == 0);
- return static_cast<T*>(mem);
-}
-
enum class ParsePublicKeyResult {
kParsePublicOk,
kParsePublicNotRecognized,