Skip to content

Commit

Permalink
tls: fix tlsSocket.setMaxSendFragment abort
Browse files Browse the repository at this point in the history
PR-URL: #38170
Fixes: #38169
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
eladkishon authored and targos committed Apr 29, 2021
1 parent 2eef587 commit f6745e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
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

0 comments on commit f6745e9

Please sign in to comment.