Skip to content

Commit 097aea4

Browse files
committed
net: fix abort on bad address input
1 parent 1e2905f commit 097aea4

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

lib/net.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,10 @@ function internalConnect(
872872

873873
var err;
874874

875+
if (typeof address !== 'string') {
876+
throw new TypeError('Invalid address: ' + address);
877+
}
878+
875879
if (localAddress || localPort) {
876880
debug('binding to localAddress: %s and localPort: %d (addressType: %d)',
877881
localAddress, localPort, addressType);

test/parallel/test-net-better-error-messages-path.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
const common = require('../common');
33
const net = require('net');
44
const assert = require('assert');
5-
const fp = '/tmp/fadagagsdfgsdf';
6-
const c = net.connect(fp);
75

8-
c.on('connect', common.mustNotCall());
6+
{
7+
const fp = '/tmp/fadagagsdfgsdf';
8+
const c = net.connect(fp);
99

10-
c.on('error', common.mustCall(function(e) {
11-
assert.strictEqual(e.code, 'ENOENT');
12-
assert.strictEqual(e.message, `connect ENOENT ${fp}`);
13-
}));
10+
c.on('connect', common.mustNotCall());
11+
c.on('error', common.mustCall(function(e) {
12+
assert.strictEqual(e.code, 'ENOENT');
13+
assert.strictEqual(e.message, `connect ENOENT ${fp}`);
14+
}));
15+
}
16+
17+
{
18+
try {
19+
net.createConnection({ path: {} });
20+
throw new Error('UNREACHABLE');
21+
} catch (e) {
22+
assert.strictEqual(e.message, 'Invalid address: [object Object]');
23+
}
24+
}

0 commit comments

Comments
 (0)