crypto: don't call callback twice in case crypto.randomBytes fails#40157
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If
randomBytesfails, 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
RandomBytesJobfail consistently, but this commit is quite small. PS. I'm a first-time contributor to this project.