Skip to content

Commit 089a1cb

Browse files
mscdexevanlucas
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 17b8381 commit 089a1cb

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
functionnormalizeConnectArgs(args){
7575
varoptions={};
7676

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

0 commit comments

Comments
(0)