Skip to content

Commit

Permalink
net: fix abort on bad address input
Browse files Browse the repository at this point in the history
  • Loading branch information
BridgeAR committed Jun 16, 2017
1 parent 1e2905f commit 097aea4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,10 @@ function internalConnect(

var err;

if (typeof address !== 'string') {
throw new TypeError('Invalid address: ' + address);
}

if (localAddress || localPort) {
debug('binding to localAddress: %s and localPort: %d (addressType: %d)',
localAddress, localPort, addressType);
Expand Down
25 changes: 18 additions & 7 deletions test/parallel/test-net-better-error-messages-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
const common = require('../common');
const net = require('net');
const assert = require('assert');
const fp = '/tmp/fadagagsdfgsdf';
const c = net.connect(fp);

c.on('connect', common.mustNotCall());
{
const fp = '/tmp/fadagagsdfgsdf';
const c = net.connect(fp);

c.on('error', common.mustCall(function(e) {
assert.strictEqual(e.code, 'ENOENT');
assert.strictEqual(e.message, `connect ENOENT ${fp}`);
}));
c.on('connect', common.mustNotCall());
c.on('error', common.mustCall(function(e) {
assert.strictEqual(e.code, 'ENOENT');
assert.strictEqual(e.message, `connect ENOENT ${fp}`);
}));
}

{
try {
net.createConnection({ path: {} });
throw new Error('UNREACHABLE');
} catch (e) {
assert.strictEqual(e.message, 'Invalid address: [object Object]');
}
}

0 comments on commit 097aea4

Please sign in to comment.