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 2025-03-11 23:48:27 +09:00 committed by GitHub
parent 491eb66cdc
commit c3ed292d17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

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);
}

View File

@ -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',
});
}