From 4972126d958589fc3592570457689ded42af64db Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Wed, 14 Apr 2021 22:18:43 +0000 Subject: [PATCH] merge bitcoin#21677: Avoid use of low file descriptor ids (which may be in use) in FuzzedSock --- src/test/fuzz/util.h | 6 +++--- src/test/util/net.h | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index cfee6af8c5..7229b6e51d 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -536,15 +536,15 @@ class FuzzedSock : public Sock public: explicit FuzzedSock(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider{fuzzed_data_provider} { - m_socket = fuzzed_data_provider.ConsumeIntegral(); + m_socket = fuzzed_data_provider.ConsumeIntegralInRange(INVALID_SOCKET - 1, INVALID_SOCKET); } ~FuzzedSock() override { // Sock::~Sock() will be called after FuzzedSock::~FuzzedSock() and it will call // Sock::Reset() (not FuzzedSock::Reset()!) which will call CloseSocket(m_socket). - // Avoid closing an arbitrary file descriptor (m_socket is just a random number which - // may concide with a real opened file descriptor). + // Avoid closing an arbitrary file descriptor (m_socket is just a random very high number which + // theoretically may concide with a real opened file descriptor). Reset(); } diff --git a/src/test/util/net.h b/src/test/util/net.h index 03382c6df1..8403ea9608 100644 --- a/src/test/util/net.h +++ b/src/test/util/net.h @@ -70,8 +70,7 @@ public: explicit StaticContentsSock(const std::string& contents) : m_contents{contents}, m_consumed{0} { // Just a dummy number that is not INVALID_SOCKET. - static_assert(INVALID_SOCKET != 1000); - m_socket = 1000; + m_socket = INVALID_SOCKET - 1; } ~StaticContentsSock() override { Reset(); }