aboutsummaryrefslogtreecommitdiff
path: root/testprogs/fuzz/fuzz_filter.c
diff options
context:
space:
mode:
Diffstat (limited to 'testprogs/fuzz/fuzz_filter.c')
-rw-r--r--testprogs/fuzz/fuzz_filter.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/testprogs/fuzz/fuzz_filter.c b/testprogs/fuzz/fuzz_filter.c
new file mode 100644
index 000000000000..de350672797f
--- /dev/null
+++ b/testprogs/fuzz/fuzz_filter.c
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <pcap/pcap.h>
+
+void fuzz_openFile(const char * name){
+ //do nothing
+}
+
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ pcap_t * pkts;
+ struct bpf_program bpf;
+ char * filter;
+
+ //we need at least 1 byte for linktype
+ if (Size < 1) {
+ return 0;
+ }
+
+ //initialize structure snaplen = 65535
+ pkts = pcap_open_dead(Data[Size-1], 0xFFFF);
+ if (pkts == NULL) {
+ printf("pcap_open_dead failed\n");
+ return 0;
+ }
+ filter = malloc(Size);
+ memcpy(filter, Data, Size);
+ //null terminate string
+ filter[Size-1] = 0;
+
+ if (pcap_compile(pkts, &bpf, filter, 1, PCAP_NETMASK_UNKNOWN) == 0) {
+ pcap_setfilter(pkts, &bpf);
+ pcap_close(pkts);
+ pcap_freecode(&bpf);
+ }
+ else {
+ pcap_close(pkts);
+ }
+ free(filter);
+
+ return 0;
+}