-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: fix segfault on destroy after partial read
OnRead() calls into JS land which can result in the SSL context object being destroyed on return. Check that `ssl_ != nullptr` afterwards. Fixes: #11885 PR-URL: #11898 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
7d507db
commit 31dc04e
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) { | ||
common.skip('missing crypto'); | ||
return; | ||
} | ||
|
||
const fs = require('fs'); | ||
const net = require('net'); | ||
const tls = require('tls'); | ||
|
||
const key = fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'); | ||
const cert = fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'); | ||
const secureContext = tls.createSecureContext({ key, cert }); | ||
|
||
const server = net.createServer(common.mustCall((conn) => { | ||
const options = { isServer: true, secureContext, server }; | ||
const socket = new tls.TLSSocket(conn, options); | ||
socket.once('data', common.mustCall(() => { | ||
socket._destroySSL(); // Should not crash. | ||
server.close(); | ||
})); | ||
})); | ||
|
||
server.listen(0, function() { | ||
const options = { | ||
port: this.address().port, | ||
rejectUnauthorized: false, | ||
}; | ||
tls.connect(options, function() { | ||
this.write('*'.repeat(1 << 20)); // Write more data than fits in a frame. | ||
this.on('error', this.destroy); // Server closes connection on us. | ||
}); | ||
}); |