From 72ff6d2b506aede4ac0e6a19f31f87c622173f50 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Tue, 10 Dec 2024 12:52:33 +0100 Subject: [PATCH] fuzz: change FuzzedSock::GetSockName() to always fully set the output It would be somewhat broken OS if `getsockname()` returns `0` (success) and returns `sa_family` as `AF_INET` and only sets e.g. 2 bytes in the output. --- src/test/fuzz/util/net.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/fuzz/util/net.cpp b/src/test/fuzz/util/net.cpp index 85c9cbb30c..af2b703619 100644 --- a/src/test/fuzz/util/net.cpp +++ b/src/test/fuzz/util/net.cpp @@ -376,7 +376,9 @@ int FuzzedSock::GetSockName(sockaddr* name, socklen_t* name_len) const SetFuzzedErrNo(m_fuzzed_data_provider, getsockname_errnos); return -1; } - *name_len = m_fuzzed_data_provider.ConsumeData(name, *name_len); + std::memcpy(name, + ConsumeFixedLengthByteVector(m_fuzzed_data_provider, *name_len).data(), + *name_len); return 0; }