Skip to content

Commit d905c61

Browse files
deokjinkimUlisesGascon
authored andcommitted
tls: use validateFunction for options.SNICallback
If user uses invalid type for `options.SNICallback` in TLSSocket(), it's not internal issue of Node.js. So validateFunction() is more proper than assert(). PR-URL: #50530 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 3844af2 commit d905c61

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎lib/_tls_wrap.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ TLSSocket.prototype._init = function(socket, wrap) {
909909
options.SNICallback&&
910910
(options.SNICallback!==SNICallback||
911911
(options.server&&options.server._contexts.length))){
912-
assert(typeofoptions.SNICallback==='function');
912+
validateFunction(options.SNICallback,'options.SNICallback');
913913
this._SNICallback=options.SNICallback;
914914
ssl.enableCertCb();
915915
}

‎test/parallel/test-tls-snicallback-error.js‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ if (!common.hasCrypto)
44
common.skip('missing crypto');
55

66
constassert=require('assert');
7+
constnet=require('net');
78
consttls=require('tls');
89

9-
['fhqwhgads',42,{},[]].forEach((testValue)=>{
10-
assert.throws(
11-
()=>{tls.createServer({SNICallback: testValue});},
12-
{code: 'ERR_INVALID_ARG_TYPE',message: /\boptions\.SNICallback\b/}
13-
);
14-
});
10+
for(constSNICallbackof['fhqwhgads',42,{},[]]){
11+
assert.throws(()=>{
12+
tls.createServer({ SNICallback });
13+
},{
14+
code: 'ERR_INVALID_ARG_TYPE',
15+
name: 'TypeError',
16+
});
17+
18+
assert.throws(()=>{
19+
newtls.TLSSocket(newnet.Socket(),{isServer: true, SNICallback });
20+
},{
21+
code: 'ERR_INVALID_ARG_TYPE',
22+
name: 'TypeError',
23+
});
24+
}

0 commit comments

Comments
 (0)