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

Add fuzzer targeting load_file #2762

Merged
merged 1 commit into from
Jul 24, 2023
Merged
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
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;
}