From 34985a1cbd62669dfc07905af8dcc7f5a6529fd8 Mon Sep 17 00:00:00 2001 From: Karl Skomski Date: Wed, 12 Aug 2015 15:30:01 +0200 Subject: [PATCH] crypto: fix mem {de}allocation in ExportChallenge Use correct deallocator for returned buffera. Don't free internal structure via ASN1_STRING_data. Deallocate NETSCAPE_SPKI. PR-URL: https://github.com/nodejs/node/pull/2359 Reviewed-By: Fedor Indutny --- src/node_crypto.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5275021..0e4fc45 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5281,10 +5281,12 @@ const char* Certificate::ExportChallenge(const char* data, int len) { if (sp == nullptr) return nullptr; - const char* buf = nullptr; - buf = reinterpret_cast(ASN1_STRING_data(sp->spkac->challenge)); + unsigned char* buf = nullptr; + ASN1_STRING_to_UTF8(&buf, sp->spkac->challenge); - return buf; + NETSCAPE_SPKI_free(sp); + + return reinterpret_cast(buf); } @@ -5311,7 +5313,7 @@ void Certificate::ExportChallenge(const FunctionCallbackInfo& args) { Local outString = Encode(env->isolate(), cert, strlen(cert), BUFFER); - delete[] cert; + OPENSSL_free(const_cast(cert)); args.GetReturnValue().Set(outString); } -- 2.7.4