Skip to content

Commit

Permalink
dgram: fix possibly deoptimizing use of arguments
Browse files Browse the repository at this point in the history
This commit adds a guard against an out of bounds access of
arguments, and replaces another use of arguments with a named
function parameter.

Refs: #10323
PR-URL: #11242
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
vsemozhetbyt authored and MylesBorins committed Mar 9, 2017
1 parent 336f1bd commit e5d1e27
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function replaceHandle(self, newHandle) {
self._handle = newHandle;
}

Socket.prototype.bind = function(port_ /*, address, callback*/) {
Socket.prototype.bind = function(port_, address_ /*, callback*/) {
let port = port_;

this._healthCheck();
Expand All @@ -144,7 +144,7 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {

this._bindState = BIND_STATE_BINDING;

if (typeof arguments[arguments.length - 1] === 'function')
if (arguments.length && typeof arguments[arguments.length - 1] === 'function')
this.once('listening', arguments[arguments.length - 1]);

if (port instanceof UDP) {
Expand All @@ -161,7 +161,7 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
exclusive = !!port.exclusive;
port = port.port;
} else {
address = typeof arguments[1] === 'function' ? '' : arguments[1];
address = typeof address_ === 'function' ? '' : address_;
exclusive = false;
}

Expand Down

0 comments on commit e5d1e27

Please sign in to comment.