Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0716944

Browse filesBrowse files
cjihrigBridgeAR
authored andcommitted
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>
1 parent e1fc9b9 commit 0716944
Copy full SHA for 0716944

File tree

Expand file treeCollapse file tree

2 files changed

+21
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-9
lines changed
Open diff view settings
Collapse file

‎lib/dgram.js‎

Copy file name to clipboardExpand all lines: lib/dgram.js
+12-9Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,19 @@ Socket.prototype.send = function(buffer,
561561
port = offset;
562562
address = length;
563563
}
564-
} else if (typeof length === 'number') {
565-
buffer = sliceBuffer(buffer, offset, length);
566-
if (typeof port === 'function') {
567-
callback = port;
568-
port = null;
569-
} else if (port || address) {
570-
throw new ERR_SOCKET_DGRAM_IS_CONNECTED();
571-
}
572564
} else {
573-
callback = offset;
565+
if (typeof length === 'number') {
566+
buffer = sliceBuffer(buffer, offset, length);
567+
if (typeof port === 'function') {
568+
callback = port;
569+
port = null;
570+
}
571+
} else {
572+
callback = offset;
573+
}
574+
575+
if (port || address)
576+
throw new ERR_SOCKET_DGRAM_IS_CONNECTED();
574577
}
575578

576579
if (!Array.isArray(buffer)) {
Collapse file

‎test/parallel/test-dgram-send-bad-arguments.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-dgram-send-bad-arguments.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ function checkArgs(connected) {
6868
message: 'Already connected'
6969
}
7070
);
71+
72+
common.expectsError(
73+
() => { sock.send(buf, 1234, '127.0.0.1', common.mustNotCall()); },
74+
{
75+
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
76+
type: Error,
77+
message: 'Already connected'
78+
}
79+
);
7180
} else {
7281
assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError);
7382
assert.throws(() => { sock.send(buf, 1, 1, 0, host); }, RangeError);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.