Skip to content

Commit

Permalink
net: check autoSelectFamilyAttemptTimeout is positive
Browse files Browse the repository at this point in the history
In document, `autoSelectFamilyAttemptTimeout` is described as
positive integer because it's time unit. But there is no checking
whether it's positive integer.

PR-URL: #45740
Refs: https://github.com/nodejs/node/blob/main/doc/api/net.md#socketconnectoptions-connectlistener
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
deokjinkim authored and targos committed Dec 13, 2022
1 parent 4c51c5c commit b9c2fc7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ function lookupAndConnect(self, options) {
}

if (autoSelectFamilyAttemptTimeout !== undefined) {
validateInt32(autoSelectFamilyAttemptTimeout);
validateInt32(autoSelectFamilyAttemptTimeout, 'options.autoSelectFamilyAttemptTimeout', 1);

if (autoSelectFamilyAttemptTimeout < 10) {
autoSelectFamilyAttemptTimeout = 10;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
require('../common');
const assert = require('assert');
const net = require('net');

for (const autoSelectFamilyAttemptTimeout of [-10, 0]) {
assert.throws(() => {
net.connect({
port: 8080,
autoSelectFamily: true,
autoSelectFamilyAttemptTimeout,
});
}, { code: 'ERR_OUT_OF_RANGE' });
}

0 comments on commit b9c2fc7

Please sign in to comment.