From a69397bfccec0807310a48caa79ae98ea0a630e3 Mon Sep 17 00:00:00 2001 From: Guilherme Bernal Date: Sun, 19 Sep 2021 17:38:41 -0300 Subject: [PATCH] crypto: don't call callback twice in case crypto.randomBytes fails --- lib/internal/crypto/random.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index c45d53c796d26a..8812120091f930 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -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); }); }