Skip to content

Commit aef67cf

Browse files
vsemozhetbytitaloacasas
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 <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5f1a568 commit aef67cf

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
@@ -131,7 +131,7 @@ function replaceHandle(self, newHandle) {
131131
self._handle = newHandle;
132132
}
133133

134-
Socket.prototype.bind = function(port_ /*, address, callback*/) {
134+
Socket.prototype.bind = function(port_, address_ /*, callback*/) {
135135
let port = port_;
136136

137137
this._healthCheck();
@@ -141,7 +141,7 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
141141

142142
this._bindState = BIND_STATE_BINDING;
143143

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

147147
if (port instanceof UDP) {
@@ -158,7 +158,7 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
158158
exclusive = !!port.exclusive;
159159
port = port.port;
160160
} else {
161-
address = typeof arguments[1] === 'function' ? '' : arguments[1];
161+
address = typeof address_ === 'function' ? '' : address_;
162162
exclusive = false;
163163
}
164164

0 commit comments

Comments
 (0)