Skip to content

Commit f9e121e

Browse files
vsemozhetbytMylesBorins
authored andcommitted
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: #10323
1 parent 2c84601 commit f9e121e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/dgram.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function replaceHandle(self, newHandle) {
134134
self._handle = newHandle;
135135
}
136136

137-
Socket.prototype.bind = function(port_ /*, address, callback*/) {
137+
Socket.prototype.bind = function(port_, address_ /*, callback*/) {
138138
var self = this;
139139
let port = port_;
140140

@@ -145,7 +145,7 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
145145

146146
this._bindState = BIND_STATE_BINDING;
147147

148-
if (typeof arguments[arguments.length - 1] === 'function')
148+
if (arguments.length && typeof arguments[arguments.length - 1] === 'function')
149149
self.once('listening', arguments[arguments.length - 1]);
150150

151151
if (port instanceof UDP) {
@@ -162,7 +162,7 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
162162
exclusive = !!port.exclusive;
163163
port = port.port;
164164
} else {
165-
address = typeof arguments[1] === 'function' ? '' : arguments[1];
165+
address = typeof address_ === 'function' ? '' : address_;
166166
exclusive = false;
167167
}
168168

0 commit comments

Comments
 (0)