Skip to content

Commit 2d72a45

Browse files
committed
crypto: fix mem {de}allocation in ExportChallenge
Use correct deallocator for returned buffer Don't free internal structure via ASN1_STRING_data Deallocate NETSCAPE_SPKI
1 parent 847459c commit 2d72a45

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/node_crypto.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -5252,10 +5252,12 @@ const char* Certificate::ExportChallenge(const char* data, int len) {
52525252
if (sp == nullptr)
52535253
return nullptr;
52545254

5255-
const char* buf = nullptr;
5256-
buf = reinterpret_cast<const char*>(ASN1_STRING_data(sp->spkac->challenge));
5255+
unsigned char* buf = nullptr;
5256+
ASN1_STRING_to_UTF8(&buf, sp->spkac->challenge);
52575257

5258-
return buf;
5258+
NETSCAPE_SPKI_free(sp);
5259+
5260+
return reinterpret_cast<const char*>(buf);
52595261
}
52605262

52615263

@@ -5282,7 +5284,7 @@ void Certificate::ExportChallenge(const FunctionCallbackInfo<Value>& args) {
52825284

52835285
Local<Value> outString = Encode(env->isolate(), cert, strlen(cert), BUFFER);
52845286

5285-
delete[] cert;
5287+
OPENSSL_free(const_cast<char*>(cert));
52865288

52875289
args.GetReturnValue().Set(outString);
52885290
}

0 commit comments

Comments
 (0)