mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-26 15:51:13 +02:00
Avoid use of low file descriptor ids (which may be in use) in FuzzedSock and StaticContentsSock
This commit is contained in:
@@ -577,15 +577,15 @@ class FuzzedSock : public Sock
|
|||||||
public:
|
public:
|
||||||
explicit FuzzedSock(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider{fuzzed_data_provider}
|
explicit FuzzedSock(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider{fuzzed_data_provider}
|
||||||
{
|
{
|
||||||
m_socket = fuzzed_data_provider.ConsumeIntegral<SOCKET>();
|
m_socket = fuzzed_data_provider.ConsumeIntegralInRange<SOCKET>(INVALID_SOCKET - 1, INVALID_SOCKET);
|
||||||
}
|
}
|
||||||
|
|
||||||
~FuzzedSock() override
|
~FuzzedSock() override
|
||||||
{
|
{
|
||||||
// Sock::~Sock() will be called after FuzzedSock::~FuzzedSock() and it will call
|
// Sock::~Sock() will be called after FuzzedSock::~FuzzedSock() and it will call
|
||||||
// Sock::Reset() (not FuzzedSock::Reset()!) which will call CloseSocket(m_socket).
|
// 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
|
// Avoid closing an arbitrary file descriptor (m_socket is just a random very high number which
|
||||||
// may concide with a real opened file descriptor).
|
// theoretically may concide with a real opened file descriptor).
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -78,8 +78,7 @@ public:
|
|||||||
explicit StaticContentsSock(const std::string& contents) : m_contents{contents}, m_consumed{0}
|
explicit StaticContentsSock(const std::string& contents) : m_contents{contents}, m_consumed{0}
|
||||||
{
|
{
|
||||||
// Just a dummy number that is not INVALID_SOCKET.
|
// Just a dummy number that is not INVALID_SOCKET.
|
||||||
static_assert(INVALID_SOCKET != 1000);
|
m_socket = INVALID_SOCKET - 1;
|
||||||
m_socket = 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~StaticContentsSock() override { Reset(); }
|
~StaticContentsSock() override { Reset(); }
|
||||||
|
Reference in New Issue
Block a user