Skip to content

Commit 4762f4a

Browse files
daeyeontargos
authored andcommitted
net: validate non-string host for socket.connect
Signed-off-by: Daeyeon Jeong <[email protected]> PR-URL: #57198 Reviewed-By: James M Snell <[email protected]>
1 parent 1c271b1 commit 4762f4a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

‎lib/net.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,8 @@ function lookupAndConnect(self, options){
13111311
consthost=options.host||'localhost';
13121312
let{ port, autoSelectFamilyAttemptTimeout, autoSelectFamily }=options;
13131313

1314+
validateString(host,'options.host');
1315+
13141316
if(localAddress&&!isIP(localAddress)){
13151317
thrownewERR_INVALID_IP_ADDRESS(localAddress);
13161318
}

‎test/parallel/test-net-connect-options-invalid.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ const net = require('net');
2525
});
2626
});
2727
}
28+
29+
{
30+
assert.throws(()=>{
31+
net.createConnection({
32+
host: ['192.168.0.1'],
33+
port: 8080,
34+
});
35+
},{
36+
code: 'ERR_INVALID_ARG_TYPE',
37+
name: 'TypeError',
38+
});
39+
}

0 commit comments

Comments
(0)