Skip to content

Commit b23d414

Browse files
krydosaddaleax
authored andcommitted
tls: do not wrap net.Socket with StreamWrap
Fixes: #3655 PR-URL: #12799 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
1 parent ef16319 commit b23d414

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/_tls_wrap.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const util = require('util');
3131
const common = require('_tls_common');
3232
const StreamWrap = require('_stream_wrap').StreamWrap;
3333
const Buffer = require('buffer').Buffer;
34-
const Duplex = require('stream').Duplex;
3534
const debug = util.debuglog('tls');
3635
const Timer = process.binding('timer_wrap').Timer;
3736
const tls_wrap = process.binding('tls_wrap');
@@ -275,12 +274,10 @@ function TLSSocket(socket, options) {
275274

276275
// Wrap plain JS Stream into StreamWrap
277276
var wrap;
278-
if (!(socket instanceof net.Socket) && socket instanceof Duplex)
279-
wrap = new StreamWrap(socket);
280-
else if ((socket instanceof net.Socket) && !socket._handle)
281-
wrap = new StreamWrap(socket);
282-
else
277+
if ((socket instanceof net.Socket && socket._handle) || !socket)
283278
wrap = socket;
279+
else
280+
wrap = new StreamWrap(socket);
284281

285282
// Just a documented property to make secure sockets
286283
// distinguishable from regular ones.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
/*
4+
* Issue: https://github.com/nodejs/node/issues/3655
5+
* Test checks if we get exception instead of runtime error
6+
*/
7+
8+
require('../common');
9+
const assert = require('assert');
10+
11+
const TlsSocket = require('tls').TLSSocket;
12+
const EventEmitter = require('events').EventEmitter;
13+
assert.throws(
14+
() => { new TlsSocket(new EventEmitter()); },
15+
/^TypeError: this\.stream\.pause is not a function/
16+
);

0 commit comments

Comments
 (0)