Skip to content
Myr

jq_fuzz_parse_stream.c

This file

Path

tests/jq_fuzz_parse_stream.c

33 lines · 937 bytes · C

Last changed by

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

History of this file

Take it

1#include <stdint.h>2#include <stdlib.h>3#include <string.h>45#include "jv.h"67int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {8  // Create null-terminated string9  char *null_terminated = (char *)malloc(size + 1);10  memcpy(null_terminated, (char *)data, size);11  null_terminated[size] = '\0';1213  // 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;33}