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

crypto: don't call callback twice in case crypto.randomBytes fails #40157

Closed
wants to merge 1 commit into from

Conversation

lbguilherme
Copy link
Contributor

@lbguilherme lbguilherme commented Sep 19, 2021

const crypto = require("crypto");

crypto.randomBytes(10, (err, buf) => {
  console.log(err, buf);
});

If randomBytes fails, this code will print to the console twice. First with the error message and then a second time without any error and a buffer full of zeros.

It was introduced by #35093 (see this diff: dae283d#diff-afe151ccd22dba4dff750df92b5c0062736027ed4d23ae2eade177b5f215b9efL59-R90). It was merged on v15 and exists on v16 and master. Thus this is a regression between v14 and v16.

I don't know how to write a test for this since I don't see a way to make RandomBytesJob fail consistently, but this commit is quite small. PS. I'm a first-time contributor to this project.

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Sep 19, 2021
Copy link
Member

@tniessen tniessen left a comment

Choose a reason for hiding this comment

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

Thank you @lbguilherme, good catch!

@tniessen tniessen added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 19, 2021
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 19, 2021
@nodejs-github-bot
Copy link
Contributor

@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 19, 2021
@panva panva removed the needs-ci PRs that need a full CI run. label Sep 20, 2021
@nodejs-github-bot
Copy link
Contributor

@panva
Copy link
Member

panva commented Sep 22, 2021

Landed in 61df3d8

@panva panva closed this Sep 22, 2021
panva pushed a commit that referenced this pull request Sep 22, 2021
PR-URL: #40157
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
targos pushed a commit that referenced this pull request Oct 4, 2021
PR-URL: #40157
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. crypto Issues and PRs related to the crypto subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants