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: nullify .ssl on handle close #5168

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
3 changes: 3 additions & 0 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ proxiedMethods.forEach(function(name) {
});

tls_wrap.TLSWrap.prototype.close = function closeProxy(cb) {
if (this.owner)
this.owner.ssl = null;

if (this._parentWrap && this._parentWrap._handle === this._parent) {
this._parentWrap.once('close', cb);
return this._parentWrap.destroy();
Expand Down
45 changes: 45 additions & 0 deletions test/parallel/test-tls-regr-gh-5108.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

const common = require('../common');

if (!common.hasCrypto) {
console.log('1..0 # Skipped: node compiled without crypto.');
return;
}

const assert = require('assert');
const tls = require('tls');
const fs = require('fs');
const path = require('path');

const keyDir = path.join(common.fixturesDir, 'keys');
const key = fs.readFileSync(path.join(keyDir, 'agent1-key.pem'));
const cert = fs.readFileSync(path.join(keyDir, 'agent1-cert.pem'));

const server = tls.createServer({
key: key,
cert: cert
}, function(c) {
c.end();
}).listen(common.PORT, function() {
var client = tls.connect({
port: common.PORT,
rejectUnauthorized: false
}, common.mustCall(function() {
client.destroy();
if (!client._events.close)
client._events.close = [];
else if (!Array.isArray(client._events.close))
client._events.close = [ client._events.close ];

client._events.close.unshift(common.mustCall(function() {
setImmediate(function() {
// Make it crash on unpatched node.js
var fd = client.ssl && client.ssl.fd;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the intention is to fail the test here, why not assert it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because assert below will fail, and it won't crash.

assert(client.ssl === null);
assert(!fd);
});
}));
server.close();
}));
});