Skip to content

Commit e5d1e27

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 PR-URL: #11242 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 336f1bd commit e5d1e27

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/dgram.js

Lines changed: 3 additions & 3 deletions
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
let port = port_;
139139

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

145145
this._bindState = BIND_STATE_BINDING;
146146

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

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

0 commit comments

Comments
 (0)