jq_fuzz_execute.cpp
This file
Path
tests/jq_fuzz_execute.cpp
48 lines · 1.3 KiB · C++
Last changed by
jq_fuzz_execute: limit oniguruma depth to 1024 (#3377)Sudhakar Vermabefore adoption589a694
History of this fileTake it
The walk stopped after 200 commits: lines older than fa6a2ff point at it.
website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff
lines 1–5why, one step back1#include <fuzzer/FuzzedDataProvider.h>2#include <string>34#include "jq.h"5#include "jv.h"jq_fuzz_execute: limit oniguruma depth to 1024 (#3377)Sudhakar Vermabefore adoption589a694
lines 6–11why, one step back6#include "oniguruma.h"78extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {9 onig_set_parse_depth_limit(1024);10 return 0;11}website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff
lines 12–48why, one step back1213// Fuzzer inspired by /src/jq_test.c14// The goal is to have the fuzzer execute the functions:15// jq_compile -> jv_parse -> jq_next.16extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {17 FuzzedDataProvider fdp(data, size);18 std::string prog_payload = fdp.ConsumeRandomLengthString();19 std::string parse_payload1 = fdp.ConsumeRandomLengthString();20 std::string parse_payload2 = fdp.ConsumeRandomLengthString();2122 jq_state *jq = NULL;23 jq = jq_init();24 if (jq != NULL) {25 jq_set_attr(jq, jv_string("JQ_ORIGIN"), jv_string("/tmp/"));2627 if (jq_compile(jq, prog_payload.c_str())) {28 // Process to jv_parse and then jv_next29 jv input = jv_parse(parse_payload1.c_str());30 if (jv_is_valid(input)) {31 jq_start(jq, input, 0);32 jv next = jv_parse(parse_payload2.c_str());33 if (jv_is_valid(next)) {34 jv actual = jq_next(jq);35 jv_free(actual);36 }37 jv_free(next);38 } else {39 // Only free if input is invalid as otherwise jq_teardown40 // frees it.41 jv_free(input);42 }43 }44 }45 jq_teardown(&jq);4647 return 0;48}