Coverage Report

Created: 2025-08-28 06:51

/src/crow/tests/fuzz/template_fuzzer.cpp
Line
Count
Source
1
#include <cstdint>
2
#include <fuzzer/FuzzedDataProvider.h>
3
4
#include "crow.h"
5
6
static crow::mustache::context build_context_object(FuzzedDataProvider &fdp)
7
3.88k
{
8
3.88k
    crow::mustache::context ctx{};
9
10
6.89k
    for (auto i = 0; i < fdp.ConsumeIntegralInRange(0, 10); ++i)
11
3.00k
    {
12
3.00k
        ctx[fdp.ConsumeRandomLengthString()] = fdp.ConsumeRandomLengthString();
13
3.00k
    }
14
15
3.88k
    return ctx;
16
3.88k
}
17
18
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, const std::size_t size)
19
4.81k
{
20
4.81k
    FuzzedDataProvider fdp{data, size};
21
4.81k
    try
22
4.81k
    {
23
4.81k
        auto page = crow::mustache::compile(fdp.ConsumeRandomLengthString());
24
4.81k
        auto ctx = build_context_object(fdp);
25
4.81k
        page.render_string(ctx);
26
4.81k
    }
27
4.81k
    catch (const std::exception& e)
28
4.81k
    {
29
        // No special handling for invalid inputs or rendering errors
30
986
    }
31
32
4.81k
    return 0;
33
4.81k
}