Skip to content

Commit 6262182

Browse files
Avoid use of low file descriptor ids (which may be in use) in FuzzedSock and StaticContentsSock
1 parent e7af2f3 commit 6262182

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/test/fuzz/util.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,15 @@ class FuzzedSock : public Sock
577577
public:
578578
explicit FuzzedSock(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider{fuzzed_data_provider}
579579
{
580-
m_socket = fuzzed_data_provider.ConsumeIntegral<SOCKET>();
580+
m_socket = fuzzed_data_provider.ConsumeIntegralInRange<SOCKET>(INVALID_SOCKET - 1, INVALID_SOCKET);
581581
}
582582

583583
~FuzzedSock() override
584584
{
585585
// Sock::~Sock() will be called after FuzzedSock::~FuzzedSock() and it will call
586586
// Sock::Reset() (not FuzzedSock::Reset()!) which will call CloseSocket(m_socket).
587-
// Avoid closing an arbitrary file descriptor (m_socket is just a random number which
588-
// may concide with a real opened file descriptor).
587+
// Avoid closing an arbitrary file descriptor (m_socket is just a random very high number which
588+
// theoretically may concide with a real opened file descriptor).
589589
Reset();
590590
}
591591

src/test/util/net.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class StaticContentsSock : public Sock
7878
explicit StaticContentsSock(const std::string& contents) : m_contents{contents}, m_consumed{0}
7979
{
8080
// Just a dummy number that is not INVALID_SOCKET.
81-
static_assert(INVALID_SOCKET != 1000);
82-
m_socket = 1000;
81+
m_socket = INVALID_SOCKET - 1;
8382
}
8483

8584
~StaticContentsSock() override { Reset(); }

0 commit comments

Comments
 (0)