]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/fuzz/fuzz-json.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "alloc-util.h"
9 int LLVMFuzzerTestOneInput(const uint8_t *data
, size_t size
) {
10 _cleanup_free_
char *out
= NULL
; /* out should be freed after g */
12 _cleanup_fclose_
FILE *f
= NULL
, *g
= NULL
;
13 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
18 f
= fmemopen_unlocked((char*) data
, size
, "re");
21 if (json_parse_file(f
, NULL
, 0, &v
, NULL
, NULL
) < 0)
24 g
= open_memstream_unlocked(&out
, &out_size
);
27 json_variant_dump(v
, 0, g
, NULL
);
28 json_variant_dump(v
, JSON_FORMAT_PRETTY
|JSON_FORMAT_COLOR
|JSON_FORMAT_SOURCE
, g
, NULL
);