Skip to content

Commit 5a887d4

Browse files
committed
fuzz: avoid FuzzedSock::Recv() repeated errors with EAGAIN
If `recv(2)` returns an error (`-1`) and sets `errno` to a temporary error like `EAGAIN` a proper application code is expected to retry the operation. If the fuzz data is exhausted, then `FuzzedSock::Recv()` will keep returning `-1` and setting `errno` to the first element of `recv_errnos[]` which happened to be `EAGAIN`. This may continue forever or cause the fuzz test to run for a long time before some higher level application "receive timeout" is triggered. Thus, put `ECONNREFUSED` as first element of `recv_errnos[]`.
1 parent 3088f83 commit 5a887d4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/test/fuzz/util.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,13 @@ class FuzzedSock : public Sock
622622

623623
ssize_t Recv(void* buf, size_t len, int flags) const override
624624
{
625+
// Have a permanent error at recv_errnos[0] because when the fuzzed data is exhausted
626+
// SetFuzzedErrNo() will always return the first element and we want to avoid Recv()
627+
// returning -1 and setting errno to EAGAIN repeatedly.
625628
constexpr std::array recv_errnos{
629+
ECONNREFUSED,
626630
EAGAIN,
627631
EBADF,
628-
ECONNREFUSED,
629632
EFAULT,
630633
EINTR,
631634
EINVAL,

0 commit comments

Comments
 (0)