Skip to content

Commit 7ddbf94

Browse files
theanarkhruyadorno
authored andcommitted
dgram: check udp buffer size to avoid fd leak
PR-URL: #56084 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 4559fac commit 7ddbf94

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
@@ -59,6 +59,7 @@ const {
5959
validateString,
6060
validateNumber,
6161
validatePort,
62+
validateUint32,
6263
} = require('internal/validators');
6364
const { Buffer } = require('buffer');
6465
const { deprecate, guessHandleType, promisify, SymbolAsyncDispose, SymbolDispose } = require('internal/util');
@@ -108,6 +109,12 @@ function Socket(type, listener) {
108109
options = type;
109110
type = options.type;
110111
lookup = options.lookup;
112+
if (options.recvBufferSize) {
113+
validateUint32(options.recvBufferSize, 'options.recvBufferSize');
114+
}
115+
if (options.sendBufferSize) {
116+
validateUint32(options.sendBufferSize, 'options.sendBufferSize');
117+
}
111118
recvBufferSize = options.recvBufferSize;
112119
sendBufferSize = options.sendBufferSize;
113120
}

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)