Skip to content

Commit eadcee1

Browse files
committed
tls: throw if SNICallback is not a function
If a value is passed for SNICallback and it is not a function, createServer() will now throw. PR-URL: #20969 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 89d211f commit eadcee1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: lib/_tls_wrap.js

+5
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,11 @@ function Server(options, listener) {
896896
'options.handshakeTimeout', 'number', options.handshakeTimeout);
897897
}
898898

899+
if (this[kSNICallback] && typeof this[kSNICallback] !== 'function') {
900+
throw new ERR_INVALID_ARG_TYPE(
901+
'options.SNICallback', 'function', options.SNICallback);
902+
}
903+
899904
if (this.sessionTimeout) {
900905
this._sharedCreds.context.setSessionTimeout(this.sessionTimeout);
901906
}

Diff for: test/parallel/test-tls-snicallback-error.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto)
4+
common.skip('missing crypto');
5+
6+
if (!process.features.tls_sni)
7+
common.skip('compiled without OpenSSL or with old OpenSSL version');
8+
9+
const assert = require('assert');
10+
const tls = require('tls');
11+
12+
['fhqwhgads', 42, {}, []].forEach((testValue) => {
13+
assert.throws(
14+
() => { tls.createServer({ SNICallback: testValue }); },
15+
{ code: 'ERR_INVALID_ARG_TYPE', message: /\boptions\.SNICallback\b/ }
16+
);
17+
});

0 commit comments

Comments
 (0)