summaryrefslogtreecommitdiff
path: root/lib/dgram.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-06-08 08:48:05 -0400
committercjihrig <cjihrig@gmail.com>2019-06-10 09:14:13 -0700
commitd1dd4e10db5cb163f265a1abd1f5952f60a81e09 (patch)
tree4bede0f5121354b67b2954290ee0091eb3ac1c89 /lib/dgram.js
parentbcf11356b3d8a39a0d731164bee9b2acd4c10bae (diff)
downloadandroid-node-v8-d1dd4e10db5cb163f265a1abd1f5952f60a81e09.tar.gz
android-node-v8-d1dd4e10db5cb163f265a1abd1f5952f60a81e09.tar.bz2
android-node-v8-d1dd4e10db5cb163f265a1abd1f5952f60a81e09.zip
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>
Diffstat (limited to 'lib/dgram.js')
-rw-r--r--lib/dgram.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/dgram.js b/lib/dgram.js
index cb20c4499a..e032a6f7fd 100644
--- a/lib/dgram.js
+++ b/lib/dgram.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)) {