From eadcee11372d8228bcb203a9ab97a5f7d61d4809 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 25 May 2018 13:21:43 -0700 Subject: [PATCH] tls: throw if SNICallback is not a function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a value is passed for SNICallback and it is not a function, createServer() will now throw. PR-URL: https://github.com/nodejs/node/pull/20969 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung Reviewed-By: Luigi Pinca Reviewed-By: Ujjwal Sharma Reviewed-By: Tobias Nießen Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell --- lib/_tls_wrap.js | 5 +++++ test/parallel/test-tls-snicallback-error.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/parallel/test-tls-snicallback-error.js diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index d85d85752b6..77b37c54f0a 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -896,6 +896,11 @@ function Server(options, listener) { 'options.handshakeTimeout', 'number', options.handshakeTimeout); } + if (this[kSNICallback] && typeof this[kSNICallback] !== 'function') { + throw new ERR_INVALID_ARG_TYPE( + 'options.SNICallback', 'function', options.SNICallback); + } + if (this.sessionTimeout) { this._sharedCreds.context.setSessionTimeout(this.sessionTimeout); } diff --git a/test/parallel/test-tls-snicallback-error.js b/test/parallel/test-tls-snicallback-error.js new file mode 100644 index 00000000000..307a359ebb2 --- /dev/null +++ b/test/parallel/test-tls-snicallback-error.js @@ -0,0 +1,17 @@ +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +if (!process.features.tls_sni) + common.skip('compiled without OpenSSL or with old OpenSSL version'); + +const assert = require('assert'); +const tls = require('tls'); + +['fhqwhgads', 42, {}, []].forEach((testValue) => { + assert.throws( + () => { tls.createServer({ SNICallback: testValue }); }, + { code: 'ERR_INVALID_ARG_TYPE', message: /\boptions\.SNICallback\b/ } + ); +});