diff options
author | marcofleon <marleo23@proton.me> | 2024-05-31 14:32:39 +0100 |
---|---|---|
committer | dergoegge <n.goeggi@gmail.com> | 2024-06-03 10:32:43 +0100 |
commit | 22d0f1a27ef7733b51b3c2138a8d01713df8f248 (patch) | |
tree | 494331d0f18559ed60cf26455c21d7c29f8f83d0 | |
parent | a7fceda68bb62fe3d9060fcf52e33b2f64a2acf9 (diff) | |
download | bitcoin-22d0f1a27ef7733b51b3c2138a8d01713df8f248.tar.xz |
[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>
-rw-r--r-- | src/test/fuzz/util/net.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/test/fuzz/util/net.cpp b/src/test/fuzz/util/net.cpp index cbf549276c..5e7aae670e 100644 --- a/src/test/fuzz/util/net.cpp +++ b/src/test/fuzz/util/net.cpp @@ -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; } |