Fuzzers for a couple libnetutil functions

This commit is contained in:
dmiller 2026-08-11 22:13:34 +00:00
parent d8d0af7f0f
commit 35cf9f75e6
3 changed files with 51 additions and 0 deletions

5
fuzz/.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
fuzz_PacketParser
fuzz_dns_packet_parseFromBuffer
fuzz_ippackethdrinfo
fuzz_traceroute_decode_reply
corpus/

19
fuzz/fuzz_PacketParser.cc Normal file
View file

@ -0,0 +1,19 @@
#include "common.h"
#include "../libnetutil/PacketParser.h"
#include <stddef.h>
#include <stdint.h>
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;
}

View file

@ -0,0 +1,27 @@
#include "common.h"
#include "../libnetutil/netutil.h"
#include <stddef.h>
#include <stdint.h>
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;
}