]>
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"
8 int LLVMFuzzerTestOneInput(const uint8_t *data
, size_t size
) {
9 _cleanup_free_
char *out
= NULL
; /* out should be freed after g */
11 _cleanup_fclose_
FILE *f
= NULL
, *g
= NULL
;
12 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
17 f
= fmemopen((char*) data
, size
, "re");
20 if (json_parse_file(f
, NULL
, &v
, NULL
, NULL
) < 0)
23 g
= open_memstream(&out
, &out_size
);
26 json_variant_dump(v
, 0, g
, NULL
);
27 json_variant_dump(v
, JSON_FORMAT_PRETTY
|JSON_FORMAT_COLOR
|JSON_FORMAT_SOURCE
, g
, NULL
);