1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00
Files
stedolan-jq/tests/jq_fuzz_parse_extended.c
Emanuele Torre 460a5c12b4 jq_fuzz_parse_extended.c: don't jv_free() twice
jv_dump() frees its argument.

I missed this problem before merging #2952, whoops! =)

fixup from eb3b5654bbd285fa70bab8ca71f2284354adf625
2023-11-28 20:51:07 +01:00

37 lines
708 B
C

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "jv.h"
int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
if (size < 8) {
return 0;
}
int fuzz_flags = *(int*)data;
data += 4;
size -= 4;
int dump_flags = *(int*)data;
data += 4;
size -= 4;
// Creat null-terminated string
char *null_terminated = (char *)malloc(size + 1);
memcpy(null_terminated, (char *)data, size);
null_terminated[size] = '\0';
// Fuzzer entrypoint
jv res = jv_parse_custom_flags(null_terminated, fuzz_flags);
if (jv_is_valid(res)) {
jv_dump(res, dump_flags);
} else {
jv_free(res);
}
// Free the null-terminated string
free(null_terminated);
return 0;
}