From 09f91c0e6dd468aa2d99b4271ffe9b76116f6916 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Wed, 30 Nov 2022 23:20:12 +0700 Subject: [PATCH] fix: read item out of array `blockinfo` in miner tests (#5084) This array contains 119 items and all of them are used. But during test created one extra block that also need `blockinfo`. It is UB and trigger address sanitizer. --- src/test/miner_tests.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index ba6d91c499..29f8628724 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -88,6 +88,7 @@ constexpr static struct { {0, 0x40045af7}, {0, 0x6000df7a}, {0, 0xe00131a1}, {0, 0x40021386}, {0, 0xa00891b5}, {0, 0x60007854}, {0, 0x60021730} }; +constexpr static size_t blockinfo_size = sizeof(blockinfo) / sizeof(blockinfo[0]); static CBlockIndex CreateBlockIndex(int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { @@ -230,7 +231,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) std::vector txFirst; auto createAndProcessEmptyBlock = [&]() { - int i = ::ChainActive().Height(); + int i = ::ChainActive().Height() % blockinfo_size; CBlock *pblock = &pemptyblocktemplate->block; // pointer for convenience { LOCK(cs_main);