diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2021-04-13 12:31:49 +0200 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2022-04-15 09:14:49 +0200 |
commit | 184e56d6683d05fc84f5153cfff83a2e32883556 (patch) | |
tree | 33fe88e870ac0196ecf245be57a02e98afb0d561 /src/test/fuzz | |
parent | e14f0fa6a346afecbb1d5470aef5226a8cc33e57 (diff) |
net: add new method Sock::SetSockOpt() that wraps setsockopt()
This will help to increase `Sock` usage and make more code mockable.
Diffstat (limited to 'src/test/fuzz')
-rw-r--r-- | src/test/fuzz/util.cpp | 13 | ||||
-rw-r--r-- | src/test/fuzz/util.h | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/test/fuzz/util.cpp b/src/test/fuzz/util.cpp index 6766fbf2d9..033c6e18d5 100644 --- a/src/test/fuzz/util.cpp +++ b/src/test/fuzz/util.cpp @@ -193,6 +193,19 @@ int FuzzedSock::GetSockOpt(int level, int opt_name, void* opt_val, socklen_t* op return 0; } +int FuzzedSock::SetSockOpt(int, int, const void*, socklen_t) const +{ + constexpr std::array setsockopt_errnos{ + ENOMEM, + ENOBUFS, + }; + if (m_fuzzed_data_provider.ConsumeBool()) { + SetFuzzedErrNo(m_fuzzed_data_provider, setsockopt_errnos); + return -1; + } + return 0; +} + bool FuzzedSock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const { constexpr std::array wait_errnos{ diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index 6c91844633..580105e442 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -68,6 +68,8 @@ public: int GetSockOpt(int level, int opt_name, void* opt_val, socklen_t* opt_len) const override; + int SetSockOpt(int level, int opt_name, const void* opt_val, socklen_t opt_len) const override; + bool Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred = nullptr) const override; bool IsConnected(std::string& errmsg) const override; |