Skip to content

Commit

Permalink
tls: copy the Buffer object before using
Browse files Browse the repository at this point in the history
`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]>
  • Loading branch information
thefourtheye authored and Myles Borins committed Oct 11, 2016
1 parent 1b318e8 commit 2847490
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exports.convertNPNProtocols = function convertNPNProtocols(NPNProtocols, out) {

// If it's already a Buffer - store it
if (NPNProtocols instanceof Buffer) {
out.NPNProtocols = NPNProtocols;
out.NPNProtocols = Buffer.from(NPNProtocols);
}
};

Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-tls-basic-validations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}

const assert = require('assert');
const tls = require('tls');

{
const buffer = Buffer.from('abcd');
const out = {};
tls.convertNPNProtocols(buffer, out);
out.NPNProtocols.write('efgh');
assert(buffer.equals(Buffer.from('abcd')));
assert(out.NPNProtocols.equals(Buffer.from('efgh')));
}

0 comments on commit 2847490

Please sign in to comment.