2018-08-01 12:25:26 +02:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
|
|
|
|
|
|
#include "alloc-util.h"
|
2019-04-04 12:24:38 +02:00
|
|
|
#include "fileio.h"
|
2018-08-01 12:25:26 +02:00
|
|
|
#include "fd-util.h"
|
|
|
|
#include "fuzz.h"
|
|
|
|
#include "json.h"
|
|
|
|
|
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|
|
|
_cleanup_free_ char *out = NULL; /* out should be freed after g */
|
|
|
|
size_t out_size;
|
|
|
|
_cleanup_fclose_ FILE *f = NULL, *g = NULL;
|
|
|
|
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
|
|
|
|
2019-04-04 12:24:38 +02:00
|
|
|
f = fmemopen_unlocked((char*) data, size, "re");
|
2018-08-01 12:25:26 +02:00
|
|
|
assert_se(f);
|
|
|
|
|
2019-01-08 18:48:48 +01:00
|
|
|
if (json_parse_file(f, NULL, 0, &v, NULL, NULL) < 0)
|
2018-08-01 12:25:26 +02:00
|
|
|
return 0;
|
|
|
|
|
2019-04-04 12:24:38 +02:00
|
|
|
g = open_memstream_unlocked(&out, &out_size);
|
2018-08-01 12:25:26 +02:00
|
|
|
assert_se(g);
|
|
|
|
|
|
|
|
json_variant_dump(v, 0, g, NULL);
|
|
|
|
json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR|JSON_FORMAT_SOURCE, g, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|