Skip to content
suit Documentation
Login

Documentation

// Fuzz target for the suit.lint parser: whatever parses stays within the
// limits, and every forbidden text is refused by the scanner it feeds.

#include "lint.h"
#include "platform.h"

#include <stdint.h>
#include <string.h>

static LintRules rules;

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
    LintError e;
    if (!lint_rules_parse(&rules, (const char *)data, size, &e)) {
        ensure(e.msg[0] != '\0' && rules.n_allow == 0 && rules.n_forbid == 0);
        return 0;
    }
    ensure(rules.n_allow <= LINT_ALLOW_MAX && rules.n_forbid <= LINT_FORBID_MAX);
    for (uint32_t i = 0; i < rules.n_allow; i++) ensure(lint_allowed(&rules, rules.allow[i]));
    for (uint32_t i = 0; i < rules.n_forbid; i++) {
        [[maybe_unused]] size_t n = strlen(rules.forbid[i]);
        ensure(n > 0 && n <= LINT_TEXT_MAX && lint_line(&rules, rules.forbid[i], n) != nullptr);
    }
    return 0;
}