Skip to content

Commit

Permalink
crypto: fix mem {de}allocation in ExportChallenge
Browse files Browse the repository at this point in the history
Use correct deallocator for returned buffer
Don't free internal structure via ASN1_STRING_data
Deallocate NETSCAPE_SPKI
  • Loading branch information
skomski committed Aug 20, 2015
1 parent 847459c commit 2d72a45
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5252,10 +5252,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);
}


Expand All @@ -5282,7 +5284,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);
}
Expand Down

0 comments on commit 2d72a45

Please sign in to comment.