From 7968c7930165d55af89a18a80de24a3aa78abb11 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/40157 Reviewed-By: Anna Henningsen Reviewed-By: Tobias Nießen Reviewed-By: Filip Skokan Reviewed-By: James M Snell Reviewed-By: Robert Nagy --- 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); }); }