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 <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 89d211f commit eadcee1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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
}
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)