Skip to content

Commit a206afe

Browse files
committed
net: add length check when normalizing args
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>
1 parent d28159f commit a206afe

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/net.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ exports.connect = exports.createConnection = function() {
7474
function normalizeConnectArgs(args) {
7575
var options = {};
7676

77-
if (args[0] !== null && typeof args[0] === 'object') {
77+
if (args.length === 0) {
78+
return [options];
79+
} else if (args[0] !== null && typeof args[0] === 'object') {
7880
// connect(options, [cb])
7981
options = args[0];
8082
} else if (isPipeName(args[0])) {
@@ -83,7 +85,7 @@ function normalizeConnectArgs(args) {
8385
} else {
8486
// connect(port, [host], [cb])
8587
options.port = args[0];
86-
if (typeof args[1] === 'string') {
88+
if (args.length > 1 && typeof args[1] === 'string') {
8789
options.host = args[1];
8890
}
8991
}

0 commit comments

Comments
 (0)