0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

net: add length check when normalizing args

This helps to prevent possible deoptimizations that arise when trying
to access nonexistent indices.

PR-URL: https://github.com/nodejs/node/pull/8112
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Brian White 2016-08-15 13:46:39 -04:00
parent d28159f0fc
commit a206afec76
No known key found for this signature in database
GPG Key ID: 606D7358F94DA209

View File

@ -74,7 +74,9 @@ exports.connect = exports.createConnection = function() {
function normalizeConnectArgs(args) {
var options = {};
if (args[0] !== null && typeof args[0] === 'object') {
if (args.length === 0) {
return [options];
} else if (args[0] !== null && typeof args[0] === 'object') {
// connect(options, [cb])
options = args[0];
} else if (isPipeName(args[0])) {
@ -83,7 +85,7 @@ function normalizeConnectArgs(args) {
} else {
// connect(port, [host], [cb])
options.port = args[0];
if (typeof args[1] === 'string') {
if (args.length > 1 && typeof args[1] === 'string') {
options.host = args[1];
}
}