summaryrefslogtreecommitdiffstats
path: root/tests/jq_fuzz_compile.c
blob: 9d10148f592555bdd42aeb19ec42174ca827af93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "jq.h"

int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
  // Creat null-terminated string
  char *null_terminated = (char *)malloc(size + 1);
  memcpy(null_terminated, (char *)data, size);
  null_terminated[size] = '\0';

  // Fuzzer entrypoint
  jq_state *jq = NULL;
  jq = jq_init();
  if (jq != NULL) {
    if (jq_compile(jq, null_terminated)) {
      jq_dump_disassembly(jq, 2);
    }
  }
  jq_teardown(&jq);

  // Free the null-terminated string
  free(null_terminated);

  return 0;
}