Skip to content

Commit

Permalink
crypto: don't call callback twice in case crypto.randomBytes fails
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lbguilherme authored and panva committed Sep 22, 2021
1 parent 36e2ffe commit 61df3d8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/crypto/random.js
Expand Up @@ -102,7 +102,7 @@ function randomBytes(size, callback) {

// Keep the callback as a regular function so this is propagated.
randomFill(buf.buffer, 0, size, function(error) {
if (error) FunctionPrototypeCall(callback, this, error);
if (error) return FunctionPrototypeCall(callback, this, error);
FunctionPrototypeCall(callback, this, null, buf);
});
}
Expand Down

0 comments on commit 61df3d8

Please sign in to comment.