Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: check arg types of renegotiate() #25876

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/_tls_wrap.js
Expand Up @@ -39,6 +39,7 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
const { SecureContext: NativeSecureContext } = internalBinding('crypto');
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CALLBACK,
ERR_MULTIPLE_CALLBACK,
ERR_SOCKET_CLOSED,
ERR_TLS_DH_PARAM_SIZE,
Expand Down Expand Up @@ -560,6 +561,11 @@ 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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support null here? I think just undefined would be enough.

Copy link
Contributor Author

@sam-github sam-github Feb 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @cjihrig, I just saw the approved state, not this comment. I see your point, should I open another PR to change this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's your call. It's not a huge deal, but I do think null implies a mistake or different intention from undefined.

throw new ERR_INVALID_CALLBACK();

if (this.destroyed)
return;

Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-tls-disable-renegotiation.js
Expand Up @@ -47,6 +47,22 @@ server.listen(0, common.mustCall(() => {
};
const client = tls.connect(options, common.mustCall(() => {
client.write('');

common.expectsError(() => client.renegotiate(), {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
});

common.expectsError(() => client.renegotiate(common.mustNotCall()), {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
});

common.expectsError(() => client.renegotiate({}, false), {
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) => {
Expand Down