jq_fuzz_execute.cpp
This file
Path
tests/jq_fuzz_execute.cpp
38 lines · 1.1 KiB · C++
Last changed by
jq_fuzz_execute: cleanup un-needed externDavid Korczynskibefore adoptionbfb7fd5
History of this fileTake it
Add fuzzer targeting jq_nextDavid Korczynskibefore adoption252ab24
lines 1–38why, one step back1#include <fuzzer/FuzzedDataProvider.h>2#include <string>34#include "jq.h"5#include "jv.h"67// Fuzzer inspired by /src/jq_test.c8// The goal is to have the fuzzer execute the functions:9// jq_compile -> jv_parse -> jq_next.10extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {11 FuzzedDataProvider fdp(data, size);12 std::string prog_payload = fdp.ConsumeRandomLengthString();13 std::string parse_payload1 = fdp.ConsumeRandomLengthString();14 std::string parse_payload2 = fdp.ConsumeRandomLengthString();1516 jq_state *jq = NULL;17 jq = jq_init();18 if (jq != NULL) {19 if (jq_compile(jq, prog_payload.c_str())) {20 // Process to jv_parse and then jv_next21 jv input = jv_parse(parse_payload1.c_str());22 if (jv_is_valid(input)) {23 jq_start(jq, input, 0);24 jv next = jv_parse(parse_payload2.c_str());25 if (jv_is_valid(next)) {26 jv actual = jq_next(jq);27 jv_free(actual);28 }29 jv_free(next);30 }3132 // Do not free "input" as this is handled by jq_teardown.33 }34 }35 jq_teardown(&jq);3637 return 0;38}