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: fix tlsSocket.setMaxSendFragment results in an abort #38170

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ const {
const {
validateBuffer,
validateCallback,
validateInt32,
validateObject,
validateString,
validateUint32
validateUint32,
} = require('internal/validators');
const {
InternalX509Certificate
Expand Down Expand Up @@ -893,6 +894,7 @@ TLSSocket.prototype.exportKeyingMaterial = function(length, label, context) {
};

TLSSocket.prototype.setMaxSendFragment = function setMaxSendFragment(size) {
validateInt32(size, 'size');
return this._handle.setMaxSendFragment(size) === 1;
};

Expand Down
27 changes: 25 additions & 2 deletions test/parallel/test-tls-max-send-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,38 @@ const buf = Buffer.allocUnsafe(10000);
let received = 0;
const maxChunk = 768;

const invalidArgumentError = {
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE'
};

const server = tls.createServer({
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem')
}, function(c) {
// Lower and upper limits

// No size is passed.
assert.throws(() => c.setMaxSendFragment(), invalidArgumentError);

// Invalid arg is passed.
[null, undefined, '', {}, false, true, []].forEach((arg) => {
assert.throws(() => c.setMaxSendFragment(arg), invalidArgumentError);
});

[NaN, Infinity, 2 ** 31].forEach((arg) => {
assert.throws(() => c.setMaxSendFragment(arg), {
name: 'RangeError',
code: 'ERR_OUT_OF_RANGE'
});
});

assert.throws(() => c.setMaxSendFragment(Symbol()), { name: 'TypeError' });

// Lower and upper limits.
assert(!c.setMaxSendFragment(511));
assert(!c.setMaxSendFragment(16385));

// Correct fragment size
// Correct fragment size.
assert(c.setMaxSendFragment(maxChunk));

c.end(buf);
Expand Down