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‎

Lines changed: 6 additions & 0 deletions
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||typeofoptions!=='object')
586+
thrownewERR_INVALID_ARG_TYPE('options','Object',options);
587+
if(callback!=null&&typeofcallback!=='function')
588+
thrownewERR_INVALID_CALLBACK();
589+
584590
if(this.destroyed)
585591
return;
586592

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ server.listen(0, common.mustCall(() =>{
4747
};
4848
constclient=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
letok=client.renegotiate(options,common.mustCall((err)=>{

0 commit comments

Comments
(0)