diff --git a/fuzz/fuzz_traceroute_decode_reply.cc b/fuzz/fuzz_traceroute_decode_reply.cc new file mode 100644 index 000000000..87d70b382 --- /dev/null +++ b/fuzz/fuzz_traceroute_decode_reply.cc @@ -0,0 +1,17 @@ +#include "common.h" +#include "../traceroute.h" + +#include +#include + +extern "C" +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + fuzz_init(); + + static volatile bool ret; + ret = fuzz_decode_reply(data, size); + (void) ret; + + return 0; +} diff --git a/traceroute.cc b/traceroute.cc index 0014aadcd..7dd278cab 100644 --- a/traceroute.cc +++ b/traceroute.cc @@ -99,6 +99,9 @@ router X. The only way to be sure is to do a complete trace for each target individually. */ +#ifdef HAVE_CONFIG_H +#include "nmap_config.h" +#endif #include "nmap_dns.h" #include "nmap_error.h" #include "nmap_tty.h" @@ -1208,6 +1211,13 @@ static bool decode_reply(const u8 *ip, unsigned int len, Reply *reply) { return true; } +#ifdef ENABLE_FUZZING +bool fuzz_decode_reply(const u8 *ip, unsigned int len) { + global_id = 0; + Reply reply; + return decode_reply(ip, len, &reply); +} +#endif static bool read_reply(Reply *reply, pcap_t *pd, long timeout) { const u8 *ip; diff --git a/traceroute.h b/traceroute.h index 7c0cee668..da3c9908b 100644 --- a/traceroute.h +++ b/traceroute.h @@ -71,4 +71,5 @@ int traceroute(std::vector &Targets); void traceroute_hop_cache_clear(); +bool fuzz_decode_reply(const uint8_t *ip, unsigned int len); #endif