From a206afec7671944d5b123d207e00300a894fe0df Mon Sep 17 00:00:00 2001 From: Brian White Date: Mon, 15 Aug 2016 13:46:39 -0400 Subject: [PATCH] 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 Reviewed-By: Evan Lucas Reviewed-By: James M Snell --- lib/net.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/net.js b/lib/net.js index ca220e4725..a218ad17b4 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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]; } }