Skip to content

Commit 43434d4

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 6c1175a commit 43434d4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/net.js

+2
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,8 @@ function lookupAndConnect(self, options) {
13111311
const host = options.host || 'localhost';
13121312
let { port, autoSelectFamilyAttemptTimeout, autoSelectFamily } = options;
13131313

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

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

+12
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)