fuzz: Check for addrv1 compatibility before using addrv1 serializer
This commit is contained in:
parent
d67883d01e
commit
903f3d0627
1 changed files with 9 additions and 5 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
#include <merkleblock.h>
|
#include <merkleblock.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
|
#include <netbase.h>
|
||||||
#include <node/utxo_snapshot.h>
|
#include <node/utxo_snapshot.h>
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <protocol.h>
|
#include <protocol.h>
|
||||||
|
@ -44,9 +45,9 @@ struct invalid_fuzzing_input_exception : public std::exception {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
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;
|
ds << obj;
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
@ -79,9 +80,9 @@ void DeserializeFromFuzzingInput(const std::vector<uint8_t>& buffer, T& obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
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
|
} // namespace
|
||||||
|
@ -183,7 +184,10 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
#elif NETADDR_DESERIALIZE
|
#elif NETADDR_DESERIALIZE
|
||||||
CNetAddr na;
|
CNetAddr na;
|
||||||
DeserializeFromFuzzingInput(buffer, na);
|
DeserializeFromFuzzingInput(buffer, na);
|
||||||
AssertEqualAfterSerializeDeserialize(na);
|
if (na.IsAddrV1Compatible()) {
|
||||||
|
AssertEqualAfterSerializeDeserialize(na);
|
||||||
|
}
|
||||||
|
AssertEqualAfterSerializeDeserialize(na, INIT_PROTO_VERSION | ADDRV2_FORMAT);
|
||||||
#elif SERVICE_DESERIALIZE
|
#elif SERVICE_DESERIALIZE
|
||||||
CService s;
|
CService s;
|
||||||
DeserializeFromFuzzingInput(buffer, s);
|
DeserializeFromFuzzingInput(buffer, s);
|
||||||
|
|
Loading…
Reference in a new issue