net: fix abort on bad address input
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
22cf25cf2d
commit
f40caf7282
14
lib/net.js
14
lib/net.js
@ -42,6 +42,7 @@ const WriteWrap = process.binding('stream_wrap').WriteWrap;
|
|||||||
const async_id_symbol = process.binding('async_wrap').async_id_symbol;
|
const async_id_symbol = process.binding('async_wrap').async_id_symbol;
|
||||||
const { newUid, setInitTriggerId } = require('async_hooks');
|
const { newUid, setInitTriggerId } = require('async_hooks');
|
||||||
const nextTick = require('internal/process/next_tick').nextTick;
|
const nextTick = require('internal/process/next_tick').nextTick;
|
||||||
|
const errors = require('internal/errors');
|
||||||
|
|
||||||
var cluster;
|
var cluster;
|
||||||
var dns;
|
var dns;
|
||||||
@ -964,8 +965,9 @@ Socket.prototype.connect = function() {
|
|||||||
this._sockname = null;
|
this._sockname = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pipe = !!options.path;
|
const path = options.path;
|
||||||
debug('pipe', pipe, options.path);
|
var pipe = !!path;
|
||||||
|
debug('pipe', pipe, path);
|
||||||
|
|
||||||
if (!this._handle) {
|
if (!this._handle) {
|
||||||
this._handle = pipe ? new Pipe() : new TCP();
|
this._handle = pipe ? new Pipe() : new TCP();
|
||||||
@ -982,7 +984,13 @@ Socket.prototype.connect = function() {
|
|||||||
this.writable = true;
|
this.writable = true;
|
||||||
|
|
||||||
if (pipe) {
|
if (pipe) {
|
||||||
internalConnect(this, options.path);
|
if (typeof path !== 'string') {
|
||||||
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
|
||||||
|
'options.path',
|
||||||
|
'string',
|
||||||
|
path);
|
||||||
|
}
|
||||||
|
internalConnect(this, path);
|
||||||
} else {
|
} else {
|
||||||
lookupAndConnect(this, options);
|
lookupAndConnect(this, options);
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,21 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const assert = require('assert');
|
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) {
|
c.on('connect', common.mustNotCall());
|
||||||
assert.strictEqual(e.code, 'ENOENT');
|
c.on('error', common.expectsError({
|
||||||
assert.strictEqual(e.message, `connect ENOENT ${fp}`);
|
code: 'ENOENT',
|
||||||
}));
|
message: `connect ENOENT ${fp}`
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
assert.throws(
|
||||||
|
() => net.createConnection({ path: {} }),
|
||||||
|
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE' })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user