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 <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>
1 parent 7cde322 commit 792acc1

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

‎lib/net.js‎

Lines changed: 7 additions & 3 deletions
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-
varpipe=!!options.path;
916-
debug('pipe',pipe,options.path);
915+
constpath=options.path;
916+
varpipe=!!path;
917+
debug('pipe',pipe,path);
917918

918919
if(!this._handle){
919920
this._handle=pipe ? newPipe() : newTCP();
@@ -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(typeofpath!=='string'){
935+
thrownewTypeError('"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‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
constcommon=require('../common');
33
constnet=require('net');
44
constassert=require('assert');
5-
constfp='/tmp/fadagagsdfgsdf';
6-
constc=net.connect(fp);
75

8-
c.on('connect',common.mustNotCall());
6+
{
7+
constfp='/tmp/fadagagsdfgsdf';
8+
constc=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"optionmustbeastring:\[objectObject]/
21+
);
22+
}

0 commit comments

Comments
 (0)