dgram: fix abort on bad args
This commit fixes a C++ abort for connected dgram sockets by improving input validation in the JS layer. Fixes: https://github.com/nodejs/node/issues/28126 PR-URL: https://github.com/nodejs/node/pull/28135 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
bcf11356b3
commit
d1dd4e10db
@ -561,18 +561,21 @@ Socket.prototype.send = function(buffer,
|
||||
port = offset;
|
||||
address = length;
|
||||
}
|
||||
} else if (typeof length === 'number') {
|
||||
} else {
|
||||
if (typeof length === 'number') {
|
||||
buffer = sliceBuffer(buffer, offset, length);
|
||||
if (typeof port === 'function') {
|
||||
callback = port;
|
||||
port = null;
|
||||
} else if (port || address) {
|
||||
throw new ERR_SOCKET_DGRAM_IS_CONNECTED();
|
||||
}
|
||||
} else {
|
||||
callback = offset;
|
||||
}
|
||||
|
||||
if (port || address)
|
||||
throw new ERR_SOCKET_DGRAM_IS_CONNECTED();
|
||||
}
|
||||
|
||||
if (!Array.isArray(buffer)) {
|
||||
if (typeof buffer === 'string') {
|
||||
list = [ Buffer.from(buffer) ];
|
||||
|
@ -68,6 +68,15 @@ function checkArgs(connected) {
|
||||
message: 'Already connected'
|
||||
}
|
||||
);
|
||||
|
||||
common.expectsError(
|
||||
() => { sock.send(buf, 1234, '127.0.0.1', common.mustNotCall()); },
|
||||
{
|
||||
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
|
||||
type: Error,
|
||||
message: 'Already connected'
|
||||
}
|
||||
);
|
||||
} else {
|
||||
assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError);
|
||||
assert.throws(() => { sock.send(buf, 1, 1, 0, host); }, RangeError);
|
||||
|
Loading…
x
Reference in New Issue
Block a user