Permalink
Browse files

net: fix abort on bad address input

Backport-PR-URL: #14390
PR-URL: #13726
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
BridgeAR authored and MylesBorins committed Jun 16, 2017
1 parent 7cde322 commit 792acc17bf0f8573f97d80528c2fa677b9f84966
Showing with 23 additions and 10 deletions.
  1. +7 −3 lib/net.js
  2. +16 −7 test/parallel/test-net-better-error-messages-path.js
View
@@ -912,8 +912,9 @@ Socket.prototype.connect = function(options, cb) {
this._sockname = null;
}
var pipe = !!options.path;
debug('pipe', pipe, options.path);
const path = options.path;
var pipe = !!path;
debug('pipe', pipe, path);
if (!this._handle) {
this._handle = pipe ? new Pipe() : new TCP();
@@ -930,7 +931,10 @@ Socket.prototype.connect = function(options, cb) {
this.writable = true;
if (pipe) {
connect(this, options.path);
if (typeof path !== 'string') {
throw new TypeError('"path" option must be a string: ' + path);
}
connect(this, path);
} else {
lookupAndConnect(this, options);
}
@@ -2,12 +2,21 @@
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}`);
}));
}
{
assert.throws(
() => net.createConnection({ path: {} }),
/"path" option must be a string: \[object Object]/
);
}

0 comments on commit 792acc1

Please sign in to comment.