jq_fuzz_execute.cpp
This file
Path
tests/jq_fuzz_execute.cpp
42 lines · 1.2 KiB · C++
Last changed by
jq_fuzz_execute.cpp: fix false assertDavidKorczynskibefore adoption20a403e
History of this fileTake it
Add fuzzer targeting jq_nextDavid Korczynskibefore adoption252ab24
lines 1–18why, 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) {jq_fuzz_execute.cpp: fix false assertDavidKorczynskibefore adoption20a403e
lines 19–20why, one step back19 jq_set_attr(jq, jv_string("JQ_ORIGIN"), jv_string("/tmp/"));20Add fuzzer targeting jq_nextDavid Korczynskibefore adoption252ab24
lines 21–31why, one step back21 if (jq_compile(jq, prog_payload.c_str())) {22 // Process to jv_parse and then jv_next23 jv input = jv_parse(parse_payload1.c_str());24 if (jv_is_valid(input)) {25 jq_start(jq, input, 0);26 jv next = jv_parse(parse_payload2.c_str());27 if (jv_is_valid(next)) {28 jv actual = jq_next(jq);29 jv_free(actual);30 }31 jv_free(next);jq_fuzz_execute: fix memory leakDavidKorczynskibefore adoption693a726
lines 32–35why, one step back32 } else {33 // Only free if input is invalid as otherwise jq_teardown34 // frees it.35 jv_free(input);Add fuzzer targeting jq_nextDavid Korczynskibefore adoption252ab24
lines 36–42why, one step back36 }37 }38 }39 jq_teardown(&jq);4041 return 0;42}