mirror of
https://github.com/nmap/nmap.git
synced 2026-10-24 12:53:49 +00:00
Fuzzers for a couple libnetutil functions
This commit is contained in:
parent
d8d0af7f0f
commit
35cf9f75e6
3 changed files with 51 additions and 0 deletions
5
fuzz/.gitignore
vendored
Normal file
5
fuzz/.gitignore
vendored
Normal 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
19
fuzz/fuzz_PacketParser.cc
Normal 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;
|
||||
}
|
||||
27
fuzz/fuzz_ippackethdrinfo.cc
Normal file
27
fuzz/fuzz_ippackethdrinfo.cc
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue