mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-15 16:33:52 +02:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user