Skip to content
Myr

fix jq_fuzz_parse_stream: use iterative parser API for streaming mode (#3499)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Ze Sheng · committed by GitHub · parent 1a39491 · Browse files · 1 file+17 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−5 removed

  • tests:+17 added−5 removed

1 file+17 added−5 removed

modified:tests/jq_fuzz_parse_stream.c+17 added-5 removed
3 unmodified lines
45#include "jv.h"67int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {8 // Creat null-terminated string8 // Create null-terminated string9 char *null_terminated = (char *)malloc(size + 1);10 memcpy(null_terminated, (char *)data, size);11 null_terminated[size] = '\0';1213 // Fuzzer entrypoint14 jv res = jv_parse_custom_flags(null_terminated, JV_PARSE_STREAMING);15 jv_free(res);16 13 // Use the iterative jv_parser API for streaming mode.14 // The single-shot jv_parse_custom_flags() returns "Unexpected extra JSON15 // values" for any compound JSON in streaming mode, because the streaming16 // parser produces multiple tokens but the single-shot API expects exactly17 // one value.18 jv_parser *parser = jv_parser_new(JV_PARSE_STREAMING);19 jv_parser_set_buf(parser, null_terminated, (int)size, 0);2021 jv value;22 while (jv_is_valid(value = jv_parser_next(parser))) {23 jv_free(value);24 }25 jv_free(value);2627 jv_parser_free(parser);2829 // Free the null-terminated string30 free(null_terminated);3132 return 0;
1 unmodified line