From 07a4e94e8488979c942769874b6325542388a7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 25 Nov 2023 20:57:53 +0100 Subject: [PATCH] src: assert return value of BN_bn2binpad Every other invocation of BN_bn2binpad checks the return value. For safety and consistency, do so in RandomPrimeTraits::EncodeOutput() as well. PR-URL: https://github.com/nodejs/node/pull/50860 Reviewed-By: Filip Skokan Reviewed-By: Luigi Pinca --- src/crypto/crypto_random.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/crypto/crypto_random.cc b/src/crypto/crypto_random.cc index 245f3529186964..48154df7dc91ed 100644 --- a/src/crypto/crypto_random.cc +++ b/src/crypto/crypto_random.cc @@ -75,10 +75,10 @@ Maybe RandomPrimeTraits::EncodeOutput( size_t size = BN_num_bytes(params.prime.get()); std::shared_ptr store = ArrayBuffer::NewBackingStore(env->isolate(), size); - BN_bn2binpad( - params.prime.get(), - reinterpret_cast(store->Data()), - size); + CHECK_EQ(static_cast(size), + BN_bn2binpad(params.prime.get(), + reinterpret_cast(store->Data()), + size)); *result = ArrayBuffer::New(env->isolate(), store); return Just(true); }