Skip to content

Commit 7b133d6

Browse files
theanarkhtargos
authored andcommitted
dgram: check udp buffer size to avoid fd leak
PR-URL: #56084 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 26ab8e9 commit 7b133d6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/dgram.js

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const {
6161
validateString,
6262
validateNumber,
6363
validatePort,
64+
validateUint32,
6465
} = require('internal/validators');
6566
const { Buffer } = require('buffer');
6667
const { deprecate, guessHandleType, promisify } = require('internal/util');
@@ -110,6 +111,12 @@ function Socket(type, listener) {
110111
options = type;
111112
type = options.type;
112113
lookup = options.lookup;
114+
if (options.recvBufferSize) {
115+
validateUint32(options.recvBufferSize, 'options.recvBufferSize');
116+
}
117+
if (options.sendBufferSize) {
118+
validateUint32(options.sendBufferSize, 'options.sendBufferSize');
119+
}
113120
recvBufferSize = options.recvBufferSize;
114121
sendBufferSize = options.sendBufferSize;
115122
}

test/parallel/test-dgram-createSocket-type.js

+13
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,16 @@ validTypes.forEach((validType) => {
5959
socket.close();
6060
}));
6161
}
62+
63+
{
64+
[
65+
{ type: 'udp4', recvBufferSize: 'invalid' },
66+
{ type: 'udp4', sendBufferSize: 'invalid' },
67+
].forEach((options) => {
68+
assert.throws(() => {
69+
dgram.createSocket(options);
70+
}, {
71+
code: 'ERR_INVALID_ARG_TYPE',
72+
});
73+
});
74+
}

0 commit comments

Comments
 (0)