Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ef1702

Browse filesBrowse 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 <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 136a967 commit 2ef1702
Copy full SHA for 2ef1702

File tree

Expand file treeCollapse file tree

2 files changed

+17
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-14
lines changed
Open diff view settings
Collapse file

‎lib/_tls_wrap.js‎

Copy file name to clipboardExpand all lines: lib/_tls_wrap.js
+1-5Lines changed: 1 addition & 5 deletions
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

Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-tls-client-mindhsize.js
+16-9Lines changed: 16 additions & 9 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.