Skip to content

Commit 2ef1702

Browse files
authored
tls: use validateNumber for options.minDHSize
If user sets invalid type for options.minDHSize in tls.connect(), it's not internal issue of Node.js. So validateNumber() is more proper than assert(). Plus, set min of validateNumber() as 1 to check minDHSize is positive. Refs: #49896 PR-URL: #49973 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 136a967 commit 2ef1702

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

lib/_tls_wrap.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1749,11 +1749,7 @@ exports.connect = function connect(...args) {
17491749
options.singleUse = true;
17501750

17511751
validateFunction(options.checkServerIdentity, 'options.checkServerIdentity');
1752-
assert(typeof options.minDHSize === 'number',
1753-
'options.minDHSize is not a number: ' + options.minDHSize);
1754-
assert(options.minDHSize > 0,
1755-
'options.minDHSize is not a positive number: ' +
1756-
options.minDHSize);
1752+
validateNumber(options.minDHSize, 'options.minDHSize', 1);
17571753

17581754
const context = options.secureContext || tls.createSecureContext(options);
17591755

test/parallel/test-tls-client-mindhsize.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,23 @@ testDHE1024();
7474
assert.throws(() => test(512, true, common.mustNotCall()),
7575
/DH parameter is less than 1024 bits/);
7676

77-
let errMessage = /minDHSize is not a positive number/;
78-
[0, -1, -Infinity, NaN].forEach((minDHSize) => {
79-
assert.throws(() => tls.connect({ minDHSize }),
80-
errMessage);
81-
});
77+
for (const minDHSize of [0, -1, -Infinity, NaN]) {
78+
assert.throws(() => {
79+
tls.connect({ minDHSize });
80+
}, {
81+
code: 'ERR_OUT_OF_RANGE',
82+
name: 'RangeError',
83+
});
84+
}
8285

83-
errMessage = /minDHSize is not a number/;
84-
[true, false, null, undefined, {}, [], '', '1'].forEach((minDHSize) => {
85-
assert.throws(() => tls.connect({ minDHSize }), errMessage);
86-
});
86+
for (const minDHSize of [true, false, null, undefined, {}, [], '', '1']) {
87+
assert.throws(() => {
88+
tls.connect({ minDHSize });
89+
}, {
90+
code: 'ERR_INVALID_ARG_TYPE',
91+
name: 'TypeError',
92+
});
93+
}
8794

8895
process.on('exit', function() {
8996
assert.strictEqual(nsuccess, 1);

0 commit comments

Comments
 (0)