Browse Source

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: https://github.com/nodejs/node/pull/8055
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
v4.x
Sakthipriyan Vairamani 9 years ago
committed by Myles Borins
parent
commit
c841b5a6b9
  1. 2
      lib/tls.js
  2. 19
      test/parallel/test-tls-basic-validations.js

2
lib/tls.js

@ -52,7 +52,7 @@ exports.convertNPNProtocols = function convertNPNProtocols(NPNProtocols, out) {
// If it's already a Buffer - store it // If it's already a Buffer - store it
if (NPNProtocols instanceof Buffer) { if (NPNProtocols instanceof Buffer) {
out.NPNProtocols = NPNProtocols; out.NPNProtocols = Buffer.from(NPNProtocols);
} }
}; };

19
test/parallel/test-tls-basic-validations.js

@ -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')));
}
Loading…
Cancel
Save