Skip to content

Commit

Permalink
Add fuzzer targeting load_file
Browse files Browse the repository at this point in the history
Signed-off-by: David Korczynski <david@adalogics.com>
  • Loading branch information
DavidKorczynski authored and emanuele6 committed Jul 24, 2023
1 parent 8a4f246 commit 97c6d28
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/jq_fuzz_load_file.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 97c6d28

Please sign in to comment.