diff --git a/src/netaddress.h b/src/netaddress.h index b06b6c65b69..debe03988c5 100644 --- a/src/netaddress.h +++ b/src/netaddress.h @@ -562,6 +562,14 @@ public: class CServiceHash { public: + CServiceHash() + : m_salt_k0{GetRand(std::numeric_limits::max())}, + m_salt_k1{GetRand(std::numeric_limits::max())} + { + } + + CServiceHash(uint64_t salt_k0, uint64_t salt_k1) : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {} + size_t operator()(const CService& a) const noexcept { CSipHasher hasher(m_salt_k0, m_salt_k1); @@ -572,8 +580,8 @@ public: } private: - const uint64_t m_salt_k0 = GetRand(std::numeric_limits::max()); - const uint64_t m_salt_k1 = GetRand(std::numeric_limits::max()); + const uint64_t m_salt_k0; + const uint64_t m_salt_k1; }; #endif // BITCOIN_NETADDRESS_H diff --git a/src/test/fuzz/netaddress.cpp b/src/test/fuzz/netaddress.cpp index 6cb81901cb3..56accbb3b9a 100644 --- a/src/test/fuzz/netaddress.cpp +++ b/src/test/fuzz/netaddress.cpp @@ -84,6 +84,8 @@ FUZZ_TARGET(netaddress) (void)service.ToString(); (void)service.ToStringIPPort(); (void)service.ToStringPort(); + (void)CServiceHash()(service); + (void)CServiceHash(0, 0)(service); const CNetAddr other_net_addr = ConsumeNetAddr(fuzzed_data_provider); (void)net_addr.GetReachabilityFrom(&other_net_addr);