Skip to content

Commit 34985a1

Browse files
skomskiindutny
authored andcommitted
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: #2359 Reviewed-By: Fedor Indutny <[email protected]>
1 parent f1810ed commit 34985a1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/node_crypto.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5281,10 +5281,12 @@ const char* Certificate::ExportChallenge(const char* data, int len) {
52815281
if (sp == nullptr)
52825282
return nullptr;
52835283

5284-
const char* buf = nullptr;
5285-
buf = reinterpret_cast<const char*>(ASN1_STRING_data(sp->spkac->challenge));
5284+
unsigned char* buf = nullptr;
5285+
ASN1_STRING_to_UTF8(&buf, sp->spkac->challenge);
52865286

5287-
return buf;
5287+
NETSCAPE_SPKI_free(sp);
5288+
5289+
return reinterpret_cast<const char*>(buf);
52885290
}
52895291

52905292

@@ -5311,7 +5313,7 @@ void Certificate::ExportChallenge(const FunctionCallbackInfo<Value>& args) {
53115313

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

5314-
delete[] cert;
5316+
OPENSSL_free(const_cast<char*>(cert));
53155317

53165318
args.GetReturnValue().Set(outString);
53175319
}

0 commit comments

Comments
 (0)