aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-10-27 08:07:19 +0100
committerMarcoFalke <falke.marco@gmail.com>2020-10-27 08:07:23 +0100
commitfa463f11637739eced87ce892b59aa22e28a71d5 (patch)
tree68fcdcc72095adbc1484ff3916300e9373dd28fa
parentd67883d01e507dd22d1281f4a4860e79d6a46a47 (diff)
parent903f3d06275312aa4000b765d2287339210c61c1 (diff)
Merge #20247: fuzz: Check for addrv1 compatibility before using addrv1 serializer. Fuzz addrv2 serialization.
903f3d06275312aa4000b765d2287339210c61c1 fuzz: Check for addrv1 compatibility before using addrv1 serializer (practicalswift) Pull request description: Fuzz addrv2 address serialization. Check for addrv1 compatibility before using addrv1 serializer. Before this ``` $ src/test/fuzz/netaddr_deserialize netaddr_deserialize: test/fuzz/deserialize.cpp:84: void (anonymous namespace)::AssertEqualAfterSerializeDeserialize(const T &) [T = CNetAddr]: Assertion `Deserialize<T>(Serialize(obj)) == obj' failed. ``` After this patch: ``` $ src/test/fuzz/netaddr_deserialize … ``` ACKs for top commit: MarcoFalke: review ACK 903f3d06275312aa4000b765d2287339210c61c1 Tree-SHA512: a9ddb71cc31c877fa3dd78dbc908d1e30b4790398fefe19e6541f1fca81e8560f7a11fa099ef3943b94401974c472e523484fdf66f1c23ff2e998558ba4b65de
-rw-r--r--src/test/fuzz/deserialize.cpp14
1 files changed, 9 insertions, 5 deletions
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 <key.h>
#include <merkleblock.h>
#include <net.h>
+#include <netbase.h>
#include <node/utxo_snapshot.h>
#include <primitives/block.h>
#include <protocol.h>
@@ -44,9 +45,9 @@ struct invalid_fuzzing_input_exception : public std::exception {
};
template <typename T>
-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<uint8_t>& buffer, T& obj)
}
template <typename T>
-void AssertEqualAfterSerializeDeserialize(const T& obj)
+void AssertEqualAfterSerializeDeserialize(const T& obj, const int version = INIT_PROTO_VERSION)
{
- assert(Deserialize<T>(Serialize(obj)) == obj);
+ assert(Deserialize<T>(Serialize(obj, version)) == obj);
}
} // namespace
@@ -183,7 +184,10 @@ void test_one_input(const std::vector<uint8_t>& 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);