From: Karl Skomski Date: Wed, 12 Aug 2015 13:30:01 +0000 (+0200) Subject: crypto: fix mem {de}allocation in ExportChallenge X-Git-Tag: v4.0.0-rc.1~148 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=34985a1cbd62669dfc07905af8dcc7f5a6529fd8;p=platform%2Fupstream%2Fnodejs.git 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 --- 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); }