fuzz: simplify FuzzedSock::m_peek_data

`FuzzedSock::m_peek_data` need not be an optional of a vector.
It can be just a vector whereas an empty vector denotes "no peek data".
This commit is contained in:
Vasil Dimov 2024-06-12 12:51:46 +02:00
parent 0b94fb8720
commit b51d75ea97
No known key found for this signature in database
GPG key ID: 54DF06F64B55CBBF
2 changed files with 4 additions and 4 deletions

View file

@ -191,11 +191,11 @@ ssize_t FuzzedSock::Recv(void* buf, size_t len, int flags) const
} }
std::vector<uint8_t> random_bytes; std::vector<uint8_t> random_bytes;
bool pad_to_len_bytes{m_fuzzed_data_provider.ConsumeBool()}; bool pad_to_len_bytes{m_fuzzed_data_provider.ConsumeBool()};
if (m_peek_data.has_value()) { if (!m_peek_data.empty()) {
// `MSG_PEEK` was used in the preceding `Recv()` call, return `m_peek_data`. // `MSG_PEEK` was used in the preceding `Recv()` call, return `m_peek_data`.
random_bytes = m_peek_data.value(); random_bytes = m_peek_data;
if ((flags & MSG_PEEK) == 0) { if ((flags & MSG_PEEK) == 0) {
m_peek_data.reset(); m_peek_data.clear();
} }
pad_to_len_bytes = false; pad_to_len_bytes = false;
} else if ((flags & MSG_PEEK) != 0) { } else if ((flags & MSG_PEEK) != 0) {

View file

@ -43,7 +43,7 @@ class FuzzedSock : public Sock
* If `MSG_PEEK` is used, then our `Recv()` returns some random data as usual, but on the next * If `MSG_PEEK` is used, then our `Recv()` returns some random data as usual, but on the next
* `Recv()` call we must return the same data, thus we remember it here. * `Recv()` call we must return the same data, thus we remember it here.
*/ */
mutable std::optional<std::vector<uint8_t>> m_peek_data; mutable std::vector<uint8_t> m_peek_data;
/** /**
* Whether to pretend that the socket is select(2)-able. This is randomly set in the * Whether to pretend that the socket is select(2)-able. This is randomly set in the