Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzz: improve fuzzers using pl7m #2486

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fuzz/fuzz_ndpi_reader_pl7m.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[libfuzzer]
max_len=524288
2 changes: 2 additions & 0 deletions fuzz/fuzz_ndpi_reader_pl7m_64k.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[libfuzzer]
max_len=524288
2 changes: 2 additions & 0 deletions fuzz/fuzz_ndpi_reader_pl7m_internal.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[libfuzzer]
max_len=524288
2 changes: 2 additions & 0 deletions fuzz/fuzz_ndpi_reader_pl7m_internal_simplest.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[libfuzzer]
max_len=524288
2 changes: 2 additions & 0 deletions fuzz/fuzz_ndpi_reader_pl7m_simplest.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[libfuzzer]
max_len=524288
35 changes: 21 additions & 14 deletions src/lib/third_party/src/fuzz/pl7m.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize);
#endif


/* If you want custom memory allocators, you can simply change these defines */
#define pl7m_malloc(size) malloc(size)
#define pl7m_calloc(num, size) calloc(num, size)
#define pl7m_free(p) free(p)



struct gre_header {
#if defined(__LITTLE_ENDIAN_BITFIELD)
u_int16_t rec:3,
Expand Down Expand Up @@ -402,8 +409,8 @@ static int dissect_l3(struct m_pkt *p)
switch (p->l3_proto) {
case ETH_P_IP:
ip4 = (struct ip *)data;
if (ip4->ip_v != 4 ||
data_len < 20 /* min */ ||
if (data_len < 20 /* min */ ||
ip4->ip_v != 4 ||
ip4->ip_hl < 5 ||
data_len < ip4->ip_hl * 4 ||
ntohs(ip4->ip_len) < ip4->ip_hl * 4) {
Expand Down Expand Up @@ -931,12 +938,12 @@ static struct m_pkt *__dup_pkt(struct m_pkt *p)
{
struct m_pkt *n;

n = (struct m_pkt *)malloc(sizeof(struct m_pkt));
n = (struct m_pkt *)pl7m_malloc(sizeof(struct m_pkt));
if (!n)
return NULL;
n->raw_data = (unsigned char *)malloc(MAX_PKT_LENGTH);
n->raw_data = (unsigned char *)pl7m_malloc(MAX_PKT_LENGTH);
if(!n->raw_data) {
free(n);
pl7m_free(n);
return NULL;
}
memcpy(n->raw_data, p->raw_data, p->header.caplen);
Expand All @@ -960,8 +967,8 @@ static struct m_pkt *__dup_pkt(struct m_pkt *p)
}
static void __free_pkt(struct m_pkt *p)
{
free(p->raw_data);
free(p);
pl7m_free(p->raw_data);
pl7m_free(p);
}
static void __add_pkt(struct pl7m_handle *h, struct m_pkt *p,
struct m_pkt *prev, struct m_pkt *next)
Expand Down Expand Up @@ -1023,7 +1030,7 @@ static void __free_m_pkts(struct pl7m_handle *h)
__free_pkt(p);
p = n;
}
free(h);
pl7m_free(h);
}

static struct m_pkt *do_pkt_actions(struct pl7m_handle *h, struct m_pkt *p, struct m_pkt **prev)
Expand Down Expand Up @@ -1167,7 +1174,7 @@ static struct pl7m_handle *__deserialize_from_fd(FILE *fd_in)
return NULL;
}

h = (struct pl7m_handle *)calloc(1, sizeof(struct pl7m_handle));
h = (struct pl7m_handle *)pl7m_calloc(1, sizeof(struct pl7m_handle));
if (!h) {
pcap_close(pcap_h);
return NULL;
Expand All @@ -1183,15 +1190,15 @@ static struct pl7m_handle *__deserialize_from_fd(FILE *fd_in)
/* Ignore current pkt, but keep going */
continue;
}
p = (struct m_pkt *)calloc(sizeof(struct m_pkt), 1);
p = (struct m_pkt *)pl7m_calloc(sizeof(struct m_pkt), 1);
if (!p) {
__free_m_pkts(h);
pcap_close(pcap_h);
return NULL;
}
p->raw_data = (unsigned char *)malloc(MAX_PKT_LENGTH);
p->raw_data = (unsigned char *)pl7m_malloc(MAX_PKT_LENGTH);
if (!p->raw_data) {
free(p);
pl7m_free(p);
__free_m_pkts(h);
pcap_close(pcap_h);
return NULL;
Expand All @@ -1205,8 +1212,8 @@ static struct pl7m_handle *__deserialize_from_fd(FILE *fd_in)
if (rc != 0) {
derr("Error dissect_do\n");
/* Ignore current pkt, but keep going */
free(p->raw_data);
free(p);
pl7m_free(p->raw_data);
pl7m_free(p);
continue;
}

Expand Down
Loading