Skip to content

Commit 77075ec

Browse files
skomskirvagg
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 d9b70f9 commit 77075ec

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
@@ -5279,10 +5279,12 @@ const char* Certificate::ExportChallenge(const char* data, int len) {
52795279
if (sp == nullptr)
52805280
return nullptr;
52815281

5282-
const char* buf = nullptr;
5283-
buf = reinterpret_cast<const char*>(ASN1_STRING_data(sp->spkac->challenge));
5282+
unsigned char* buf = nullptr;
5283+
ASN1_STRING_to_UTF8(&buf, sp->spkac->challenge);
52845284

5285-
return buf;
5285+
NETSCAPE_SPKI_free(sp);
5286+
5287+
return reinterpret_cast<const char*>(buf);
52865288
}
52875289

52885290

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

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

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

53145316
args.GetReturnValue().Set(outString);
53155317
}

0 commit comments

Comments
 (0)