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 <fedor@indutny.com>
This commit is contained in:
Karl Skomski 2015-08-12 15:30:01 +02:00 committed by Fedor Indutny
parent f1810ed1b8
commit 34985a1cbd

View File

@ -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<const char*>(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<const char*>(buf);
}
@ -5311,7 +5313,7 @@ void Certificate::ExportChallenge(const FunctionCallbackInfo<Value>& args) {
Local<Value> outString = Encode(env->isolate(), cert, strlen(cert), BUFFER);
delete[] cert;
OPENSSL_free(const_cast<char*>(cert));
args.GetReturnValue().Set(outString);
}