Skip to content

Commit 6769e69

Browse files
committed
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: nodejs#49896
1 parent 51f4ff2 commit 6769e69

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
@@ -1739,11 +1739,7 @@ exports.connect = function connect(...args) {
17391739
options.singleUse = true;
17401740

17411741
assert(typeof options.checkServerIdentity === 'function');
1742-
assert(typeof options.minDHSize === 'number',
1743-
'options.minDHSize is not a number: ' + options.minDHSize);
1744-
assert(options.minDHSize > 0,
1745-
'options.minDHSize is not a positive number: ' +
1746-
options.minDHSize);
1742+
validateNumber(options.minDHSize, 'options.minDHSize', 1);
17471743

17481744
const context = options.secureContext || tls.createSecureContext(options);
17491745

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)