]>
Commit | Line | Data |
---|---|---|
6315d12b EV |
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | ||
3 | #include "alloc-util.h" | |
673a1e6f | 4 | #include "fileio.h" |
6315d12b EV |
5 | #include "fd-util.h" |
6 | #include "fuzz.h" | |
7 | #include "json.h" | |
8 | ||
9 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | |
10 | _cleanup_free_ char *out = NULL; /* out should be freed after g */ | |
11 | size_t out_size; | |
12 | _cleanup_fclose_ FILE *f = NULL, *g = NULL; | |
13 | _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; | |
14 | ||
15 | if (size == 0) | |
16 | return 0; | |
17 | ||
673a1e6f | 18 | f = fmemopen_unlocked((char*) data, size, "re"); |
6315d12b EV |
19 | assert_se(f); |
20 | ||
d642f640 | 21 | if (json_parse_file(f, NULL, 0, &v, NULL, NULL) < 0) |
6315d12b EV |
22 | return 0; |
23 | ||
673a1e6f | 24 | g = open_memstream_unlocked(&out, &out_size); |
6315d12b EV |
25 | assert_se(g); |
26 | ||
27 | json_variant_dump(v, 0, g, NULL); | |
28 | json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR|JSON_FORMAT_SOURCE, g, NULL); | |
29 | ||
30 | return 0; | |
31 | } |