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
  • Loading branch information
theanarkh committed Nov 29, 2024
1 parent 4cf6fab commit 37fbf6d
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 37fbf6d

Please sign in to comment.