mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
[fuzz] Avoid endless waiting in FuzzedSock::{Wait,WaitMany}
Currently, when the FuzzedDataProvider of a FuzzedSock runs out of data, FuzzedSock::Wait and WaitMany will simulate endless waiting as the requested events are never simulated as occured. Fix this by simulating event occurence when ConsumeBool() returns false (e.g. when the data provider runs out). Co-authored-by: dergoegge <n.goeggi@gmail.com>
This commit is contained in:
parent
a7fceda68b
commit
22d0f1a27e
1 changed files with 8 additions and 2 deletions
|
@ -383,7 +383,10 @@ bool FuzzedSock::Wait(std::chrono::milliseconds timeout, Event requested, Event*
|
|||
return false;
|
||||
}
|
||||
if (occurred != nullptr) {
|
||||
*occurred = m_fuzzed_data_provider.ConsumeBool() ? requested : 0;
|
||||
// We simulate the requested event as occured when ConsumeBool()
|
||||
// returns false. This avoids simulating endless waiting if the
|
||||
// FuzzedDataProvider runs out of data.
|
||||
*occurred = m_fuzzed_data_provider.ConsumeBool() ? 0 : requested;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -392,7 +395,10 @@ bool FuzzedSock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& even
|
|||
{
|
||||
for (auto& [sock, events] : events_per_sock) {
|
||||
(void)sock;
|
||||
events.occurred = m_fuzzed_data_provider.ConsumeBool() ? events.requested : 0;
|
||||
// We simulate the requested event as occured when ConsumeBool()
|
||||
// returns false. This avoids simulating endless waiting if the
|
||||
// FuzzedDataProvider runs out of data.
|
||||
events.occurred = m_fuzzed_data_provider.ConsumeBool() ? 0 : events.requested;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue