From 5a887d49b2b39e59d7cce8e9d5b89c21ad694f8b Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Mon, 8 Mar 2021 11:42:24 +0100 Subject: [PATCH] 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[]`. --- src/test/fuzz/util.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index 4f44394d2b..db399abcf1 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -622,10 +622,13 @@ public: ssize_t Recv(void* buf, size_t len, int flags) const override { + // Have a permanent error at recv_errnos[0] because when the fuzzed data is exhausted + // SetFuzzedErrNo() will always return the first element and we want to avoid Recv() + // returning -1 and setting errno to EAGAIN repeatedly. constexpr std::array recv_errnos{ + ECONNREFUSED, EAGAIN, EBADF, - ECONNREFUSED, EFAULT, EINTR, EINVAL,