// Fuzz target for the config parser.
#include "conf.h"
#include "platform.h"
#include <fcntl.h>
#include <stdint.h>
static Conf conf;
static Conf part;
static Conf merged;
static Wards wards = {.n = 2};
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
static int sink = -1;
if (sink < 0) sink = sys_open("/dev/null", O_WRONLY, 0);
ConfError e;
if (conf_parse(&conf, (const char *)data, size, &e)) {
ensure(conf.nsections <= CONF_SECTION_MAX);
ensure(conf.nentries <= CONF_ENTRY_MAX);
[[maybe_unused]] bool dumped = conf_dump(&conf, sink);
ensure(dumped);
} else {
ensure(e.msg[0] != '\0');
}
// The same text as a file of one wardrobe and again as the file of a second: the
// merge and the check on the combined set find an error or keep every limit.
if (conf_parse_part(&part, (const char *)data, size, &e)) {
conf_merge_init(&merged);
[[maybe_unused]] bool once = conf_merge(&merged, &part, 0, &wards, &e);
ensure(once);
[[maybe_unused]] bool twice = conf_merge(&merged, &part, 1, &wards, &e);
ensure(twice || e.msg[0] != '\0');
ensure(merged.nsections <= CONF_SECTION_MAX && merged.nentries <= CONF_ENTRY_MAX);
(void)conf_check(&merged, &e);
}
return 0;
}