Skip to content

Commit

Permalink
dgram: check udp buffer size to avoid fd leak
Browse files Browse the repository at this point in the history
PR-URL: #56084
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
theanarkh authored Dec 2, 2024
1 parent 384fa62 commit 61e4ad5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const {
validateString,
validateNumber,
validatePort,
validateUint32,
} = require('internal/validators');
const { Buffer } = require('buffer');
const { deprecate, guessHandleType, promisify } = require('internal/util');
Expand Down Expand Up @@ -110,6 +111,12 @@ function Socket(type, listener) {
options = type;
type = options.type;
lookup = options.lookup;
if (options.recvBufferSize) {
validateUint32(options.recvBufferSize, 'options.recvBufferSize');
}
if (options.sendBufferSize) {
validateUint32(options.sendBufferSize, 'options.sendBufferSize');
}
recvBufferSize = options.recvBufferSize;
sendBufferSize = options.sendBufferSize;
}
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-dgram-createSocket-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ validTypes.forEach((validType) => {
socket.close();
}));
}

{
[
{ type: 'udp4', recvBufferSize: 'invalid' },
{ type: 'udp4', sendBufferSize: 'invalid' },
].forEach((options) => {
assert.throws(() => {
dgram.createSocket(options);
}, {
code: 'ERR_INVALID_ARG_TYPE',
});
});
}

0 comments on commit 61e4ad5

Please sign in to comment.