Skip to content
Myr

jq_fuzz_parse_extended.c

This file

Path

tests/jq_fuzz_parse_extended.c

36 lines · 708 bytes · C

Last changed by

Not known.

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  if (size < 8) {9    return 0;10  }1112  int fuzz_flags = *(int*)data;13  data += 4;14  size -= 4;15  int dump_flags = *(int*)data;16  data += 4;17  size -= 4;1819  // Creat null-terminated string20  char *null_terminated = (char *)malloc(size + 1);21  memcpy(null_terminated, (char *)data, size);22  null_terminated[size] = '\0';2324  // Fuzzer entrypoint25  jv res = jv_parse_custom_flags(null_terminated, fuzz_flags);26  if (jv_is_valid(res)) {27    jv_dump(res, dump_flags);28  } else {29    jv_free(res);30  }3132  // Free the null-terminated string33  free(null_terminated);3435  return 0;36}