Skip to content

Commit fe48415

Browse files
mscdexMylesBorins
authored andcommitted
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 <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3906206 commit fe48415

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/net.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ exports.connect = exports.createConnection = function() {
7373
function normalizeConnectArgs(args) {
7474
var options = {};
7575

76-
if (args[0] !== null && typeof args[0] === 'object') {
76+
if (args.length === 0) {
77+
return [options];
78+
} else if (args[0] !== null && typeof args[0] === 'object') {
7779
// connect(options, [cb])
7880
options = args[0];
7981
} else if (isPipeName(args[0])) {
@@ -82,7 +84,7 @@ function normalizeConnectArgs(args) {
8284
} else {
8385
// connect(port, [host], [cb])
8486
options.port = args[0];
85-
if (typeof args[1] === 'string') {
87+
if (args.length > 1 && typeof args[1] === 'string') {
8688
options.host = args[1];
8789
}
8890
}

0 commit comments

Comments
 (0)