Skip to content

Commit 6b7c402

Browse files
committed
tls: check arg types of renegotiate()
Don't throw on invalid property access if options is not provided, and ensure callback is a function. PR-URL: #25876 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent c6ecbd3 commit 6b7c402

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/_tls_wrap.js

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
3939
const { SecureContext: NativeSecureContext } = internalBinding('crypto');
4040
const {
4141
ERR_INVALID_ARG_TYPE,
42+
ERR_INVALID_CALLBACK,
4243
ERR_MULTIPLE_CALLBACK,
4344
ERR_SOCKET_CLOSED,
4445
ERR_TLS_DH_PARAM_SIZE,
@@ -581,6 +582,11 @@ TLSSocket.prototype._init = function(socket, wrap) {
581582
};
582583

583584
TLSSocket.prototype.renegotiate = function(options, callback) {
585+
if (options === null || typeof options !== 'object')
586+
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
587+
if (callback != null && typeof callback !== 'function')
588+
throw new ERR_INVALID_CALLBACK();
589+
584590
if (this.destroyed)
585591
return;
586592

test/parallel/test-tls-disable-renegotiation.js

+16
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ server.listen(0, common.mustCall(() => {
4747
};
4848
const client = tls.connect(options, common.mustCall(() => {
4949
client.write('');
50+
51+
common.expectsError(() => client.renegotiate(), {
52+
code: 'ERR_INVALID_ARG_TYPE',
53+
type: TypeError,
54+
});
55+
56+
common.expectsError(() => client.renegotiate(common.mustNotCall()), {
57+
code: 'ERR_INVALID_ARG_TYPE',
58+
type: TypeError,
59+
});
60+
61+
common.expectsError(() => client.renegotiate({}, false), {
62+
code: 'ERR_INVALID_CALLBACK',
63+
type: TypeError,
64+
});
65+
5066
// Negotiation is still permitted for this first
5167
// attempt. This should succeed.
5268
let ok = client.renegotiate(options, common.mustCall((err) => {

0 commit comments

Comments
 (0)