Skip to content

Commit

Permalink
net: add length check when normalizing args
Browse files Browse the repository at this point in the history
This helps to prevent possible deoptimizations that arise when trying
to access nonexistent indices.

PR-URL: #8112
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
mscdex authored and evanlucas committed Aug 24, 2016
1 parent 17b8381 commit 089a1cb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand All @@ -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];
}
}
Expand Down

0 comments on commit 089a1cb

Please sign in to comment.