diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2023-02-09 14:03:41 +0100 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2023-10-05 15:10:33 +0200 |
commit | c42ded3d9bda8b273780a4a81490bbf1b9e9c261 (patch) | |
tree | 0738aa13ac3d4055f5dc131e3815176148167e59 /src/test/fuzz/util | |
parent | 64d6f77907afd461d9b14ee10ab32335f4454734 (diff) |
fuzz: ConsumeNetAddr(): avoid IPv6 addresses that look like CJDNS
The fuzz testing framework runs as if `-cjdnsreachable` is set and in
this case addresses like `{net=IPv6, addr=fc...}` are not possible.
Diffstat (limited to 'src/test/fuzz/util')
-rw-r--r-- | src/test/fuzz/util/net.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/test/fuzz/util/net.cpp b/src/test/fuzz/util/net.cpp index d23e997719..5a286c05d2 100644 --- a/src/test/fuzz/util/net.cpp +++ b/src/test/fuzz/util/net.cpp @@ -36,7 +36,11 @@ CNetAddr ConsumeNetAddr(FuzzedDataProvider& fuzzed_data_provider) noexcept } else if (network == Network::NET_IPV6) { if (fuzzed_data_provider.remaining_bytes() >= 16) { in6_addr v6_addr = {}; - memcpy(v6_addr.s6_addr, fuzzed_data_provider.ConsumeBytes<uint8_t>(16).data(), 16); + auto addr_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(16); + if (addr_bytes[0] == CJDNS_PREFIX) { // Avoid generating IPv6 addresses that look like CJDNS. + addr_bytes[0] = 0x55; // Just an arbitrary number, anything != CJDNS_PREFIX would do. + } + memcpy(v6_addr.s6_addr, addr_bytes.data(), 16); net_addr = CNetAddr{v6_addr, fuzzed_data_provider.ConsumeIntegral<uint32_t>()}; } } else if (network == Network::NET_INTERNAL) { |