From d1dd4e10db5cb163f265a1abd1f5952f60a81e09 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 8 Jun 2019 08:48:05 -0400 Subject: 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 Reviewed-By: Yongsheng Zhang Reviewed-By: Ruben Bridgewater Reviewed-By: Santiago Gimeno Reviewed-By: Rich Trott Reviewed-By: James M Snell --- lib/dgram.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'lib/dgram.js') 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)) { -- cgit v1.2.3