Browse Source

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>
v4.0.0-rc
Karl Skomski 10 years ago
committed by Fedor Indutny
parent
commit
34985a1cbd
  1. 10
      src/node_crypto.cc

10
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<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);
}

Loading…
Cancel
Save