From 00d49ad673b0c4851298ef00522af60186210cfd Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 4 Feb 2019 10:13:18 -0800 Subject: [PATCH] tls: null not valid as a renegotiate callback Allow undefined as a callback, but do not allow null. PR-URL: https://github.com/nodejs/node/pull/25929 Reviewed-By: Colin Ihrig Reviewed-By: Anatoli Papirovski Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Minwoo Jung Reviewed-By: James M Snell --- lib/_tls_wrap.js | 2 +- test/parallel/test-tls-disable-renegotiation.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 365dbb9491266b..79b9c6d3951a2f 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -601,7 +601,7 @@ TLSSocket.prototype._init = function(socket, wrap) { TLSSocket.prototype.renegotiate = function(options, callback) { if (options === null || typeof options !== 'object') throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); - if (callback != null && typeof callback !== 'function') + if (callback !== undefined && typeof callback !== 'function') throw new ERR_INVALID_CALLBACK(); if (this.destroyed) diff --git a/test/parallel/test-tls-disable-renegotiation.js b/test/parallel/test-tls-disable-renegotiation.js index 42042a21bfbedb..da492713a0742a 100644 --- a/test/parallel/test-tls-disable-renegotiation.js +++ b/test/parallel/test-tls-disable-renegotiation.js @@ -63,6 +63,12 @@ server.listen(0, common.mustCall(() => { type: TypeError, }); + common.expectsError(() => client.renegotiate({}, null), { + code: 'ERR_INVALID_CALLBACK', + type: TypeError, + }); + + // Negotiation is still permitted for this first // attempt. This should succeed. let ok = client.renegotiate(options, common.mustCall((err) => {