diff options
author | Sakthipriyan Vairamani <thechargingvolcano@gmail.com> | 2016-08-10 22:16:06 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-08-18 04:40:52 +0300 |
commit | 60dcd7323f6a62d9539c4de70756a1081a123281 (patch) | |
tree | 2ccfb70934169b43e5e6db3aa39d8456de7845f2 /lib/tls.js | |
parent | 0441f2adb4debb2c8aa4dfbf9f6f32e76357b340 (diff) |
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>
Diffstat (limited to 'lib/tls.js')
-rw-r--r-- | lib/tls.js | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/tls.js b/lib/tls.js index 849daeb07f3..765e1658ea9 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -49,22 +49,19 @@ function convertProtocols(protocols) { exports.convertNPNProtocols = function(protocols, out) { // If protocols is Array - translate it into buffer if (Array.isArray(protocols)) { - protocols = convertProtocols(protocols); - } - // If it's already a Buffer - store it - if (protocols instanceof Buffer) { - out.NPNProtocols = protocols; + out.NPNProtocols = convertProtocols(protocols); + } else if (protocols instanceof Buffer) { + // Copy new buffer not to be modified by user. + out.NPNProtocols = Buffer.from(protocols); } }; exports.convertALPNProtocols = function(protocols, out) { // If protocols is Array - translate it into buffer if (Array.isArray(protocols)) { - protocols = convertProtocols(protocols); - } - // If it's already a Buffer - store it - if (protocols instanceof Buffer) { - // copy new buffer not to be modified by user + out.ALPNProtocols = convertProtocols(protocols); + } else if (protocols instanceof Buffer) { + // Copy new buffer not to be modified by user. out.ALPNProtocols = Buffer.from(protocols); } }; |