Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: do not free cert in .getCertificate() #25490

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1963,10 +1963,10 @@ void SSLWrap<Base>::GetCertificate(

Local<Object> result;

X509Pointer cert(SSL_get_certificate(w->ssl_.get()));
X509* cert = SSL_get_certificate(w->ssl_.get());

if (cert)
result = X509ToObject(env, cert.get());
if (cert != nullptr)
result = X509ToObject(env, cert);

args.GetReturnValue().Set(result);
}
Expand Down
9 changes: 7 additions & 2 deletions test/parallel/test-tls-pfx-authorizationerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ const server = tls
rejectUnauthorized: false
},
function() {
assert.strictEqual(client.getCertificate().serialNumber,
'ECC9B856270DA9A8');
for (let i = 0; i < 10; ++i) {
// Calling this repeatedly is a regression test that verifies
// that .getCertificate() does not accidentally decrease the
// reference count of the X509* certificate on the native side.
assert.strictEqual(client.getCertificate().serialNumber,
'ECC9B856270DA9A8');
}
client.end();
server.close();
}
Expand Down