Change CChain::Contains() to take reference

The `CChain::Contains()` method dereferences its input without checking,
potentially resulting in nullptr-dereference if invoked with `nullptr`.
To avoid this possibility, its input is changed to a reference instead.
Call sites are adapted accoringly, extra nullptr-check is added as
needed.
This commit is contained in:
optout
2026-01-26 13:47:37 +01:00
parent db56bcd692
commit fe2d6e25e0
12 changed files with 41 additions and 37 deletions

View File

@@ -225,7 +225,7 @@ static bool rest_headers(const std::any& context,
CChain& active_chain = chainman.ActiveChain();
tip = active_chain.Tip();
const CBlockIndex* pindex{chainman.m_blockman.LookupBlockIndex(*hash)};
while (pindex != nullptr && active_chain.Contains(pindex)) {
while (pindex != nullptr && active_chain.Contains(*pindex)) {
headers.push_back(pindex);
if (headers.size() == *parsed_count) {
break;
@@ -552,7 +552,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
LOCK(cs_main);
CChain& active_chain = chainman.ActiveChain();
const CBlockIndex* pindex{chainman.m_blockman.LookupBlockIndex(*block_hash)};
while (pindex != nullptr && active_chain.Contains(pindex)) {
while (pindex != nullptr && active_chain.Contains(*pindex)) {
headers.push_back(pindex);
if (headers.size() == *parsed_count)
break;