diff --git a/lib/dgram.js b/lib/dgram.js index 74dd83889990ca9..09630b6c901181c 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -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; } diff --git a/test/parallel/test-dgram-createSocket-type.js b/test/parallel/test-dgram-createSocket-type.js index 19bbd6c1b2b088c..bb6c9f311426640 100644 --- a/test/parallel/test-dgram-createSocket-type.js +++ b/test/parallel/test-dgram-createSocket-type.js @@ -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', + }); + }); +}