1
0
mirror of https://github.com/jqlang/jq.git synced 2025-11-06 11:09:01 +03:00
Files
jq/tests/jq_fuzz_execute.cpp
Sudhakar Verma 589a6947fa jq_fuzz_execute: limit oniguruma depth to 1024 (#3377)
Fixes #3375 - I'll also fix the oss-fuzz build for this in a PR

Signed-off-by: Sudhakar Verma <sudhakar.verma@canonical.com>
2025-10-05 12:50:42 +09:00

49 lines
1.3 KiB
C++

#include <fuzzer/FuzzedDataProvider.h>
#include <string>
#include "jq.h"
#include "jv.h"
#include "oniguruma.h"
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
onig_set_parse_depth_limit(1024);
return 0;
}
// Fuzzer inspired by /src/jq_test.c
// The goal is to have the fuzzer execute the functions:
// jq_compile -> jv_parse -> jq_next.
extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
FuzzedDataProvider fdp(data, size);
std::string prog_payload = fdp.ConsumeRandomLengthString();
std::string parse_payload1 = fdp.ConsumeRandomLengthString();
std::string parse_payload2 = fdp.ConsumeRandomLengthString();
jq_state *jq = NULL;
jq = jq_init();
if (jq != NULL) {
jq_set_attr(jq, jv_string("JQ_ORIGIN"), jv_string("/tmp/"));
if (jq_compile(jq, prog_payload.c_str())) {
// Process to jv_parse and then jv_next
jv input = jv_parse(parse_payload1.c_str());
if (jv_is_valid(input)) {
jq_start(jq, input, 0);
jv next = jv_parse(parse_payload2.c_str());
if (jv_is_valid(next)) {
jv actual = jq_next(jq);
jv_free(actual);
}
jv_free(next);
} else {
// Only free if input is invalid as otherwise jq_teardown
// frees it.
jv_free(input);
}
}
}
jq_teardown(&jq);
return 0;
}