Skip to content

Commit c841b5a

Browse files
thefourtheyeMylesBorins
authored andcommitted
tls: copy the Buffer object before using
`convertNPNProtocols` and `convertALPNProtocols' uses the `protocols` buffer object as it is, and if it is modified outside of core, it might have an impact. This patch makes a copy of the buffer object, before using it. PR-URL: #8055 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 410e083 commit c841b5a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/tls.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ exports.convertNPNProtocols = function convertNPNProtocols(NPNProtocols, out) {
5252

5353
// If it's already a Buffer - store it
5454
if (NPNProtocols instanceof Buffer) {
55-
out.NPNProtocols = NPNProtocols;
55+
out.NPNProtocols = Buffer.from(NPNProtocols);
5656
}
5757
};
5858

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto) {
5+
common.skip('missing crypto');
6+
return;
7+
}
8+
9+
const assert = require('assert');
10+
const tls = require('tls');
11+
12+
{
13+
const buffer = Buffer.from('abcd');
14+
const out = {};
15+
tls.convertNPNProtocols(buffer, out);
16+
out.NPNProtocols.write('efgh');
17+
assert(buffer.equals(Buffer.from('abcd')));
18+
assert(out.NPNProtocols.equals(Buffer.from('efgh')));
19+
}

0 commit comments

Comments
 (0)