Add fuzzer targeting load_file

Signed-off-by: David Korczynski <david@adalogics.com>
This commit is contained in:
David Korczynski authored and Emanuele Torre committed 2023-07-24 15:45:12 +02:00
1 parent 8a4f246876
commit 97c6d2848c
1 file changed
+27
+27
View File
@@ -0,0 +1,27 @@
#include <stdint.h>
#include <stdlib.h>
#include "jv.h"
int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
// Create file with fuzzer data
char filename[256];
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
FILE *fp = fopen(filename, "wb");
if (!fp) {
return 0;
}
fwrite(data, size, 1, fp);
fclose(fp);
// Fuzz the two version of jv_load_file
jv data1 = jv_load_file(filename, 1);
jv_free(data1);
jv data2 = jv_load_file(filename, 0);
jv_free(data2);
// Clean up fuzz file
unlink(filename);
return 0;
}