Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
dgram: check udp buffer size to avoid fd leak
  • Loading branch information
theanarkh committed Nov 29, 2024
commit 37fbf6de6725d14f1081b974441247e32e556a38
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',
});
});
}