From 35cf9f75e6be3cb0589708a6b78e5b909401b6b2 Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 11 Aug 2026 22:13:34 +0000 Subject: [PATCH] Fuzzers for a couple libnetutil functions --- fuzz/.gitignore | 5 +++++ fuzz/fuzz_PacketParser.cc | 19 +++++++++++++++++++ fuzz/fuzz_ippackethdrinfo.cc | 27 +++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 fuzz/.gitignore create mode 100644 fuzz/fuzz_PacketParser.cc create mode 100644 fuzz/fuzz_ippackethdrinfo.cc diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 000000000..5297d0d14 --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,5 @@ +fuzz_PacketParser +fuzz_dns_packet_parseFromBuffer +fuzz_ippackethdrinfo +fuzz_traceroute_decode_reply +corpus/ diff --git a/fuzz/fuzz_PacketParser.cc b/fuzz/fuzz_PacketParser.cc new file mode 100644 index 000000000..86d80dcf0 --- /dev/null +++ b/fuzz/fuzz_PacketParser.cc @@ -0,0 +1,19 @@ +#include "common.h" +#include "../libnetutil/PacketParser.h" + +#include +#include + +extern "C" +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + fuzz_init(); + + PacketParser pp; + PacketElement *pe = NULL; + pe = pp.split(data, size); + + pp.test_packet_parser(pe); + pp.freePacketChain(pe); + return 0; +} diff --git a/fuzz/fuzz_ippackethdrinfo.cc b/fuzz/fuzz_ippackethdrinfo.cc new file mode 100644 index 000000000..2cb16bc61 --- /dev/null +++ b/fuzz/fuzz_ippackethdrinfo.cc @@ -0,0 +1,27 @@ +#include "common.h" +#include "../libnetutil/netutil.h" + +#include +#include + +extern "C" +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + fuzz_init(); + + const int levels[] = { + LOW_DETAIL, + MEDIUM_DETAIL, + HIGH_DETAIL + }; + const char *buf = NULL; + static volatile size_t len = 0; + for (int i = 0; i < sizeof(levels)/sizeof(levels[0]); i++) { + buf = ippackethdrinfo(data, size, levels[i]); + len = strlen(buf); + if (strncmp(buf, "BOGUS", 5) == 0) + return -1; + } + + return 0; +}