Skip to content

Commit

Permalink
tls: do not wrap net.Socket with StreamWrap
Browse files Browse the repository at this point in the history
Fixes: #3655
PR-URL: #12799
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
krydos authored and addaleax committed May 15, 2017
1 parent ef16319 commit b23d414
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const util = require('util');
const common = require('_tls_common');
const StreamWrap = require('_stream_wrap').StreamWrap;
const Buffer = require('buffer').Buffer;
const Duplex = require('stream').Duplex;
const debug = util.debuglog('tls');
const Timer = process.binding('timer_wrap').Timer;
const tls_wrap = process.binding('tls_wrap');
Expand Down Expand Up @@ -275,12 +274,10 @@ function TLSSocket(socket, options) {

// Wrap plain JS Stream into StreamWrap
var wrap;
if (!(socket instanceof net.Socket) && socket instanceof Duplex)
wrap = new StreamWrap(socket);
else if ((socket instanceof net.Socket) && !socket._handle)
wrap = new StreamWrap(socket);
else
if ((socket instanceof net.Socket && socket._handle) || !socket)
wrap = socket;
else
wrap = new StreamWrap(socket);

// Just a documented property to make secure sockets
// distinguishable from regular ones.
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-tls-wrap-event-emmiter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/*
* Issue: https://github.com/nodejs/node/issues/3655
* Test checks if we get exception instead of runtime error
*/

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

const TlsSocket = require('tls').TLSSocket;
const EventEmitter = require('events').EventEmitter;
assert.throws(
() => { new TlsSocket(new EventEmitter()); },
/^TypeError: this\.stream\.pause is not a function/
);

0 comments on commit b23d414

Please sign in to comment.