Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: copy the Buffer object before using #8055

Closed
wants to merge 2 commits into from

Conversation

thefourtheye
Copy link
Contributor

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

tls

Description of change

convertNPNProtocols 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.


cc @nodejs/crypto

`convertNPNProtocols` 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.
@thefourtheye thefourtheye added the tls Issues and PRs related to the tls subsystem. label Aug 10, 2016
@jasnell
Copy link
Member

jasnell commented Aug 10, 2016

LGTM. Good catch.

@@ -53,7 +53,8 @@ exports.convertNPNProtocols = function(protocols, out) {
}
// If it's already a Buffer - store it
if (protocols instanceof Buffer) {
out.NPNProtocols = protocols;
// copy new buffer not to be modified by user
out.NPNProtocols = Buffer.from(protocols);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inefficient (in a minor way) if protocols was originally an array. In that case two buffers are created, here and in convertProtocols().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@bnoordhuis
Copy link
Member

Take-it-or-leave-it performance comment. LGTM with style nit if you want to land it as-is.

@bnoordhuis
Copy link
Member

LGTM

@bnoordhuis
Copy link
Member

Oh, you might want to update the commit log to also mention convertALPNProtocols().

@fhinkel
Copy link
Member

fhinkel commented Aug 12, 2016

LGTM

@jasnell
Copy link
Member

jasnell commented Aug 12, 2016

@jasnell
Copy link
Member

jasnell commented Aug 18, 2016

CI is green. Landing

jasnell pushed a commit that referenced this pull request Aug 18, 2016
`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 <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
@jasnell
Copy link
Member

jasnell commented Aug 18, 2016

Landed in 60dcd73

@jasnell jasnell closed this Aug 18, 2016
@thefourtheye thefourtheye deleted the tls-buffers-copied branch August 18, 2016 04:09
@thefourtheye
Copy link
Contributor Author

Thanks @jasnell :-)

evanlucas pushed a commit that referenced this pull request Aug 24, 2016
`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 <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
@MylesBorins
Copy link
Contributor

this is not backporting cleanly. Is it relevant to v4.x? I know there has been a bunch of churn on buffer

MylesBorins pushed a commit to MylesBorins/node that referenced this pull request Oct 11, 2016
`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: nodejs#8055
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
rvagg pushed a commit that referenced this pull request Oct 18, 2016
`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 <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
MylesBorins pushed a commit that referenced this pull request Oct 26, 2016
`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 <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Oct 26, 2016
MylesBorins pushed a commit that referenced this pull request Jan 19, 2017
cherry-pick c26b9af from v6-staging.

`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 <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
cherry-pick c26b9af from v6-staging.

`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 <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Jan 24, 2017
MylesBorins pushed a commit that referenced this pull request Feb 1, 2017
cherry-pick c26b9af from v6-staging.

`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 <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants