From 903f3d06275312aa4000b765d2287339210c61c1 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 26 Oct 2020 16:27:33 +0000 Subject: fuzz: Check for addrv1 compatibility before using addrv1 serializer --- src/test/fuzz/deserialize.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/test/fuzz/deserialize.cpp b/src/test/fuzz/deserialize.cpp index b799d3b43b..26c56fbadf 100644 --- a/src/test/fuzz/deserialize.cpp +++ b/src/test/fuzz/deserialize.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -44,9 +45,9 @@ struct invalid_fuzzing_input_exception : public std::exception { }; template -CDataStream Serialize(const T& obj) +CDataStream Serialize(const T& obj, const int version = INIT_PROTO_VERSION) { - CDataStream ds(SER_NETWORK, INIT_PROTO_VERSION); + CDataStream ds(SER_NETWORK, version); ds << obj; return ds; } @@ -79,9 +80,9 @@ void DeserializeFromFuzzingInput(const std::vector& buffer, T& obj) } template -void AssertEqualAfterSerializeDeserialize(const T& obj) +void AssertEqualAfterSerializeDeserialize(const T& obj, const int version = INIT_PROTO_VERSION) { - assert(Deserialize(Serialize(obj)) == obj); + assert(Deserialize(Serialize(obj, version)) == obj); } } // namespace @@ -183,7 +184,10 @@ void test_one_input(const std::vector& buffer) #elif NETADDR_DESERIALIZE CNetAddr na; DeserializeFromFuzzingInput(buffer, na); - AssertEqualAfterSerializeDeserialize(na); + if (na.IsAddrV1Compatible()) { + AssertEqualAfterSerializeDeserialize(na); + } + AssertEqualAfterSerializeDeserialize(na, INIT_PROTO_VERSION | ADDRV2_FORMAT); #elif SERVICE_DESERIALIZE CService s; DeserializeFromFuzzingInput(buffer, s); -- cgit v1.2.3