Skip to content

Commit 22d0f1a

Browse files
marcofleondergoegge
andcommitted
[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>
1 parent a7fceda commit 22d0f1a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/test/fuzz/util/net.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ bool FuzzedSock::Wait(std::chrono::milliseconds timeout, Event requested, Event*
383383
return false;
384384
}
385385
if (occurred != nullptr) {
386-
*occurred = m_fuzzed_data_provider.ConsumeBool() ? requested : 0;
386+
// We simulate the requested event as occured when ConsumeBool()
387+
// returns false. This avoids simulating endless waiting if the
388+
// FuzzedDataProvider runs out of data.
389+
*occurred = m_fuzzed_data_provider.ConsumeBool() ? 0 : requested;
387390
}
388391
return true;
389392
}
@@ -392,7 +395,10 @@ bool FuzzedSock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& even
392395
{
393396
for (auto& [sock, events] : events_per_sock) {
394397
(void)sock;
395-
events.occurred = m_fuzzed_data_provider.ConsumeBool() ? events.requested : 0;
398+
// We simulate the requested event as occured when ConsumeBool()
399+
// returns false. This avoids simulating endless waiting if the
400+
// FuzzedDataProvider runs out of data.
401+
events.occurred = m_fuzzed_data_provider.ConsumeBool() ? 0 : events.requested;
396402
}
397403
return true;
398404
}

0 commit comments

Comments
 (0)