mirror of https://github.com/nodejs/node.git
tls: fix convertALPNProtocols accepting ArrayBufferViews
PR-URL: https://github.com/nodejs/node/pull/43211 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
df5664440e
commit
15a682cc74
15
lib/tls.js
15
lib/tls.js
|
@ -54,7 +54,11 @@ const {
|
|||
} = require('internal/errors').codes;
|
||||
const internalUtil = require('internal/util');
|
||||
internalUtil.assertCrypto();
|
||||
const { isArrayBufferView } = require('internal/util/types');
|
||||
const {
|
||||
isArrayBufferView,
|
||||
isDataView,
|
||||
isUint8Array,
|
||||
} = require('internal/util/types');
|
||||
|
||||
const net = require('net');
|
||||
const { getOptionValue } = require('internal/options');
|
||||
|
@ -143,9 +147,16 @@ exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) {
|
|||
// If protocols is Array - translate it into buffer
|
||||
if (ArrayIsArray(protocols)) {
|
||||
out.ALPNProtocols = convertProtocols(protocols);
|
||||
} else if (isArrayBufferView(protocols)) {
|
||||
} else if (Buffer.isBuffer(protocols) || isUint8Array(protocols)) {
|
||||
// Copy new buffer not to be modified by user.
|
||||
out.ALPNProtocols = Buffer.from(protocols);
|
||||
} else if (isDataView(protocols)) {
|
||||
out.ALPNProtocols = Buffer.from(protocols.buffer.slice(
|
||||
protocols.byteOffset,
|
||||
protocols.byteOffset + protocols.byteLength
|
||||
));
|
||||
} else if (isArrayBufferView(protocols)) {
|
||||
out.ALPNProtocols = Buffer.from(protocols.slice().buffer);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -103,8 +103,11 @@ assert.throws(
|
|||
const inputBuffer = Buffer.from(arrayBufferViewStr.repeat(8), 'utf8');
|
||||
for (const expectView of common.getArrayBufferViews(inputBuffer)) {
|
||||
const out = {};
|
||||
const expected = Buffer.from(expectView.buffer.slice(),
|
||||
expectView.byteOffset,
|
||||
expectView.byteLength);
|
||||
tls.convertALPNProtocols(expectView, out);
|
||||
assert(out.ALPNProtocols.equals(Buffer.from(expectView)));
|
||||
assert(out.ALPNProtocols.equals(expected));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue