Skip to content

Commit 792acc1

Browse files
BridgeARMylesBorins
authored andcommitted
net: fix abort on bad address input
Backport-PR-URL: #14390 PR-URL: #13726 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7cde322 commit 792acc1

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

lib/net.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,9 @@ Socket.prototype.connect = function(options, cb) {
912912
this._sockname = null;
913913
}
914914

915-
var pipe = !!options.path;
916-
debug('pipe', pipe, options.path);
915+
const path = options.path;
916+
var pipe = !!path;
917+
debug('pipe', pipe, path);
917918

918919
if (!this._handle) {
919920
this._handle = pipe ? new Pipe() : new TCP();
@@ -930,7 +931,10 @@ Socket.prototype.connect = function(options, cb) {
930931
this.writable = true;
931932

932933
if (pipe) {
933-
connect(this, options.path);
934+
if (typeof path !== 'string') {
935+
throw new TypeError('"path" option must be a string: ' + path);
936+
}
937+
connect(this, path);
934938
} else {
935939
lookupAndConnect(this, options);
936940
}

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

+16-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
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+
assert.throws(
19+
() => net.createConnection({ path: {} }),
20+
/"path" option must be a string: \[object Object]/
21+
);
22+
}

0 commit comments

Comments
 (0)