Skip to content

Commit 0264a04

Browse files
panvaaduh95
authored andcommitted
crypto: handle XOF output allocation failure
Return an operation error when XOF output allocation fails. Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64851 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6bb4121 commit 0264a04

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/crypto/crypto_turboshake.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,11 @@ bool TurboShakeTraits::DeriveBits(Environment* env,
469469
CryptoJobMode mode,
470470
CryptoErrorStore* errors) {
471471
CHECK_GT(params.output_length, 0);
472-
char* buf = MallocOpenSSL<char>(params.output_length);
472+
char* buf = static_cast<char*>(OPENSSL_malloc(params.output_length));
473+
if (buf == nullptr) {
474+
errors->Insert(NodeCryptoError::ALLOCATION_FAILED);
475+
return false;
476+
}
473477

474478
const uint8_t* input = reinterpret_cast<const uint8_t*>(params.data.data());
475479
size_t input_len = params.data.size();
@@ -595,7 +599,11 @@ bool KangarooTwelveTraits::DeriveBits(Environment* env,
595599
return false;
596600
}
597601

598-
char* buf = MallocOpenSSL<char>(params.output_length);
602+
char* buf = static_cast<char*>(OPENSSL_malloc(params.output_length));
603+
if (buf == nullptr) {
604+
errors->Insert(NodeCryptoError::ALLOCATION_FAILED);
605+
return false;
606+
}
599607

600608
switch (params.variant) {
601609
case KangarooTwelveVariant::KT128:

0 commit comments

Comments
 (0)