diff options
author | Alexey Vishnyakov <vishnya@ispras.ru> | 2022-10-19 13:31:45 +0300 |
---|---|---|
committer | Alexey Vishnyakov <vishnya@ispras.ru> | 2022-10-19 13:31:45 +0300 |
commit | 38185c896b55613294064cf2b2b282e376749730 (patch) | |
tree | 4927e595eea5c3e8558c7e45dba959f126f45e17 /testprogs/fuzz/fuzz_pcap.c | |
parent | d09102e61a868f96fb68dea8fcf08b06388bb450 (diff) |
fuzz: Generate unique temporary file names to enable parallel fuzzing
Diffstat (limited to 'testprogs/fuzz/fuzz_pcap.c')
-rw-r--r-- | testprogs/fuzz/fuzz_pcap.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/testprogs/fuzz/fuzz_pcap.c b/testprogs/fuzz/fuzz_pcap.c index fba5312f..72a0e67f 100644 --- a/testprogs/fuzz/fuzz_pcap.c +++ b/testprogs/fuzz/fuzz_pcap.c @@ -1,7 +1,9 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <fcntl.h> #include <errno.h> +#include <unistd.h> #include <pcap/pcap.h> @@ -38,10 +40,11 @@ void fuzz_openFile(const char * name) { int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { pcap_t * pkts; char errbuf[PCAP_ERRBUF_SIZE]; + char filename[FILENAME_MAX] = { 0 }; const u_char *pkt; struct pcap_pkthdr *header; struct pcap_stat stats; - int r; + int fd = -1, r; //initialize output file if (outfile == NULL) { @@ -51,15 +54,24 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { } } + //generate temporary file name + snprintf(filename, FILENAME_MAX, "/tmp/libpcap_fuzz_pcap.XXXXXX"); + if ((fd = mkstemp(filename)) < 0) { + return 0; + } + close(fd); + //rewrite buffer to a file as libpcap does not have buffer inputs - if (bufferToFile("/tmp/fuzz.pcap", Data, Size) < 0) { + if (bufferToFile(filename, Data, Size) < 0) { + unlink(filename); return 0; } //initialize structure - pkts = pcap_open_offline("/tmp/fuzz.pcap", errbuf); + pkts = pcap_open_offline(filename, errbuf); if (pkts == NULL) { fprintf(outfile, "Couldn't open pcap file %s\n", errbuf); + unlink(filename); return 0; } @@ -76,5 +88,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { //close structure pcap_close(pkts); + unlink(filename); return 0; } |