From 9763548fa8f9ee9f470465a1c71ea1aaf3a7c787 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 27 Nov 2024 15:34:34 +0400 Subject: [PATCH] add runtime check for buffer size --- src/currency_core/basic_pow_helpers.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/currency_core/basic_pow_helpers.h b/src/currency_core/basic_pow_helpers.h index e9cc6ca5..62ba7721 100644 --- a/src/currency_core/basic_pow_helpers.h +++ b/src/currency_core/basic_pow_helpers.h @@ -37,12 +37,14 @@ namespace currency inline uint64_t get_nonce_from_blockblob(const blobdata& bd) { uint64_t nonce = 0; + CHECK_AND_ASSERT_MES(bd.size() >= CURRENCY_MINER_BLOCK_BLOB_NONCE_OFFSET + sizeof(nonce), 0, "Unexpected block buffer size = " << bd.size()); std::memcpy(&nonce, &bd[CURRENCY_MINER_BLOCK_BLOB_NONCE_OFFSET], sizeof(nonce)); return nonce; } inline void set_nonce_to_blockblob(blobdata& bd, const uint64_t nonce) { + CHECK_AND_ASSERT_MES(bd.size() >= CURRENCY_MINER_BLOCK_BLOB_NONCE_OFFSET + sizeof(nonce), void(), "Unexpected block buffer size = " << bd.size()); std::memcpy(&bd[CURRENCY_MINER_BLOCK_BLOB_NONCE_OFFSET], &nonce, sizeof(nonce)); } } \ No newline at end of file