Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4729,7 +4729,7 @@ void PeerManagerImpl::ProcessMessage(

// DoS prevention: do not allow m_orphans to grow unbounded (see CVE-2012-3789)
unsigned int nMaxOrphanTxSize = (unsigned int)std::max((int64_t)0, gArgs.GetIntArg("-maxorphantxsize", DEFAULT_MAX_ORPHAN_TRANSACTIONS_SIZE)) * 1000000;
m_orphanage.LimitOrphans(nMaxOrphanTxSize);
m_orphanage.LimitOrphans(nMaxOrphanTxSize, m_rng);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the missing RNG member before using it

This call now passes m_rng, but PeerManagerImpl does not declare any m_rng member or otherwise define that name (repo-wide search only finds this new use). As soon as net_processing.cpp is compiled, this path fails to build with an undeclared identifier; add the intended FastRandomContext member or pass an existing RNG.

Useful? React with 👍 / 👎.

} else {
LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString());
// We will continue to reject this tx since it has rejected
Expand Down
3 changes: 2 additions & 1 deletion src/test/fuzz/txorphan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void initialize_orphanage()
FUZZ_TARGET(txorphan, .init = initialize_orphanage)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
FastRandomContext limit_orphans_rng{/*fDeterministic=*/true};
SetMockTime(ConsumeTime(fuzzed_data_provider));

TxOrphanage orphanage;
Expand Down Expand Up @@ -140,7 +141,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
// test mocktime and expiry
SetMockTime(ConsumeTime(fuzzed_data_provider));
auto limit = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
orphanage.LimitOrphans(limit);
orphanage.LimitOrphans(limit, limit_orphans_rng);
Assert(orphanage.Size() <= limit);
});
}
Expand Down
7 changes: 4 additions & 3 deletions src/test/orphanage_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
}

// Test LimitOrphanTxSize() function:
orphanage.LimitOrphans(40);
FastRandomContext rng{/*fDeterministic=*/true};
orphanage.LimitOrphans(40, rng);
BOOST_CHECK(orphanage.CountOrphans() <= 40);
orphanage.LimitOrphans(10);
orphanage.LimitOrphans(10, rng);
BOOST_CHECK(orphanage.CountOrphans() <= 10);
orphanage.LimitOrphans(0);
orphanage.LimitOrphans(0, rng);
BOOST_CHECK(orphanage.CountOrphans() == 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/txorphanage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void TxOrphanage::EraseForPeer(NodeId peer)
if (nErased > 0) LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx from peer=%d\n", nErased, peer);
}

void TxOrphanage::LimitOrphans(unsigned int max_orphans_size)
void TxOrphanage::LimitOrphans(unsigned int max_orphans_size, FastRandomContext& rng)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the shadowing RNG declaration

Adding the rng parameter here leaves the existing FastRandomContext rng; declaration later in the same function body, so txorphanage.cpp redeclares the parameter name and fails to compile. Remove the local declaration and use the injected RNG for the eviction loop.

Useful? React with 👍 / 👎.

{
LOCK(m_mutex);

Expand Down
2 changes: 1 addition & 1 deletion src/txorphanage.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TxOrphanage {
bool HaveMoreWork(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);

/** Limit the orphanage to the given maximum */
void LimitOrphans(unsigned int max_orphans_size) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
void LimitOrphans(unsigned int max_orphans_size, FastRandomContext& rng) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);

/** Add any orphans that list a particular tx as a parent into a peer's work set */
void AddChildrenToWorkSet(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
Expand Down
Loading