Browse Source

dgram: fix possibly deoptimizing use of arguments

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: https://github.com/nodejs/node/issues/10323
v4.x
Vse Mozhet Byt 8 years ago
committed by Myles Borins
parent
commit
f9e121ead8
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 6
      lib/dgram.js

6
lib/dgram.js

@ -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*/) {
var self = this;
let port = port_;
@ -145,7 +145,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')
self.once('listening', arguments[arguments.length - 1]);
if (port instanceof UDP) {
@ -162,7 +162,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;
}

Loading…
Cancel
Save