Skip to content
Permalink
Browse files

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: #28126
PR-URL: #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>
  • Loading branch information...
cjihrig authored and BridgeAR committed Jun 8, 2019
1 parent e1fc9b9 commit 071694472f6d54b24dfadb0d11f34428755bec13
Showing with 21 additions and 9 deletions.
  1. +12 −9 lib/dgram.js
  2. +9 −0 test/parallel/test-dgram-send-bad-arguments.js
@@ -561,16 +561,19 @@ Socket.prototype.send = function(buffer,
port = offset;
address = length;
}
} 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 (typeof length === 'number') {
buffer = sliceBuffer(buffer, offset, length);
if (typeof port === 'function') {
callback = port;
port = null;
}
} else {
callback = offset;
}

if (port || address)
throw new ERR_SOCKET_DGRAM_IS_CONNECTED();
}

if (!Array.isArray(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);

0 comments on commit 0716944

Please sign in to comment.
You can’t perform that action at this time.