dgram: check udp buffer size to avoid fd leak

PR-URL: https://github.com/nodejs/node/pull/56084
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
theanarkh
2024-12-02 12:48:53 +08:00
committed by GitHub
parent 384fa62569
commit 61e4ad5352
2 changed files with 20 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ const {
validateString,
validateNumber,
validatePort,
validateUint32,
} = require('internal/validators');
const { Buffer } = require('buffer');
const { deprecate, guessHandleType, promisify } = require('internal/util');
@@ -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;
}

View File

@@ -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',
});
});
}