mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-04 06:12:07 +01:00
net: add new method Sock::Bind() that wraps bind()
This will help to increase `Sock` usage and make more code mockable.
This commit is contained in:
@@ -160,6 +160,26 @@ int FuzzedSock::Connect(const sockaddr*, socklen_t) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FuzzedSock::Bind(const sockaddr*, socklen_t) const
|
||||
{
|
||||
// Have a permanent error at bind_errnos[0] because when the fuzzed data is exhausted
|
||||
// SetFuzzedErrNo() will always set the global errno to bind_errnos[0]. We want to
|
||||
// avoid this method returning -1 and setting errno to a temporary error (like EAGAIN)
|
||||
// repeatedly because proper code should retry on temporary errors, leading to an
|
||||
// infinite loop.
|
||||
constexpr std::array bind_errnos{
|
||||
EACCES,
|
||||
EADDRINUSE,
|
||||
EADDRNOTAVAIL,
|
||||
EAGAIN,
|
||||
};
|
||||
if (m_fuzzed_data_provider.ConsumeBool()) {
|
||||
SetFuzzedErrNo(m_fuzzed_data_provider, bind_errnos);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<Sock> FuzzedSock::Accept(sockaddr* addr, socklen_t* addr_len) const
|
||||
{
|
||||
constexpr std::array accept_errnos{
|
||||
|
||||
Reference in New Issue
Block a user