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 danielleadams committed Jan 3, 2023
1 parent c116253 commit a1831da
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 @@ -1226,7 +1226,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 a1831da

Please sign in to comment.