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 buffera.
Don't free internal structure via ASN1_STRING_data.
Deallocate NETSCAPE_SPKI.

PR-URL: #2359
Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
skomski authored and rvagg committed Aug 21, 2015
1 parent d9b70f9 commit 77075ec
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 @@ -5279,10 +5279,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 @@ -5309,7 +5311,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 77075ec

Please sign in to comment.