net: validate non-string host for socket.connect

Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/57198
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Daeyeon Jeong authored and RafaelGSS committed 2025-04-17 10:51:34 -03:00
1 parent 69f12f9686
commit e79e67f6dc
2 files changed
+14

No files matched your search

+2
View File
@@ -1311,6 +1311,8 @@ function lookupAndConnect(self, options) {
const host = options.host || 'localhost';
let { port, autoSelectFamilyAttemptTimeout, autoSelectFamily } = options;
validateString(host, 'options.host');
if (localAddress && !isIP(localAddress)) {
throw new ERR_INVALID_IP_ADDRESS(localAddress);
}
@@ -25,3 +25,15 @@ const net = require('net');
});
});
}
{
assert.throws(() => {
net.createConnection({
host: ['192.168.0.1'],
port: 8080,
});
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
});
}