// Fuzz target for the done test: a text that parses gives an absolute path and,
// for contains, a TEXT that is not empty and sits inside the input; and the
// test written out again in its own form parses to the same test.
#include "need.h"
#include "platform.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
constexpr size_t FUZZ_MAX = 8192;
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
if (size > FUZZ_MAX) return 0;
static char in[FUZZ_MAX + 1];
static char again[FUZZ_MAX + DONE_PATH_MAX + 32];
memcpy(in, data, size);
in[size] = '\0';
char why[DONE_WHY_MAX];
DoneTest a;
if (!done_parse(&a, "/home/u", in, why, sizeof why)) {
ensure(why[0] != '\0');
return 0;
}
ensure(a.path[0] == '/');
if (a.kind == DONE_EXISTS) {
snprintf(again, sizeof again, "%s exists", a.path);
} else {
ensure(a.text_len > 0 && a.text >= in && a.text + a.text_len <= in + size);
snprintf(again, sizeof again, "%s contains \"%.*s\"", a.path, (int)a.text_len, a.text);
}
[[maybe_unused]] DoneTest b;
[[maybe_unused]] bool reparsed = done_parse(&b, "", again, why, sizeof why);
ensure(reparsed);
ensure(a.kind == b.kind && strcmp(a.path, b.path) == 0 && a.text_len == b.text_len);
ensure(a.kind == DONE_EXISTS || memcmp(a.text, b.text, a.text_len) == 0);
return 0;
}