Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2017-03-17 17:31:14 +0300
committerItalo A. Casas <me@italoacasas.com>2017-03-21 18:12:37 +0300
commitc626734409811b617d338229b4732d13cf6e00ee (patch)
treeadefaaf412e98a2bd70804bc72ae2cc8639ec3dc /test
parent0c00b655d8007fd484b0f20323a701d91d4650c3 (diff)
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: https://github.com/nodejs/node/issues/11885 PR-URL: https://github.com/nodejs/node/pull/11898 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-tls-socket-destroy.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/parallel/test-tls-socket-destroy.js b/test/parallel/test-tls-socket-destroy.js
new file mode 100644
index 00000000000..27651f8ec72
--- /dev/null
+++ b/test/parallel/test-tls-socket-destroy.js
@@ -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.
+ });
+});