Coverage Report

Created: 2026-04-09 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/json_html_serializer_fuzzer.cpp
Line
Count
Source
1
/* Copyright 2026 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
13
#include "json_html_serializer.hpp"
14
15
#include <nlohmann/json.hpp>
16
17
#include <cstddef>
18
#include <cstdint>
19
#include <optional>
20
#include <string>
21
22
// Reuse bmcweb's own SAX parser to limit depth/width
23
#include "http/parsing.hpp"
24
25
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
26
12.6k
{
27
12.6k
    if (size == 0)
28
0
    {
29
0
        return 0;
30
0
    }
31
32
12.6k
    std::string input(reinterpret_cast<const char*>(data), size);
33
34
    // Parse JSON using bmcweb's own SAX parser (with depth/width limits)
35
12.6k
    std::optional<nlohmann::json> parsed = parseStringAsJson(input);
36
37
12.6k
    if (parsed)
38
5.47k
    {
39
        // Exercise the HTML serializer on successfully parsed JSON
40
5.47k
        std::string html;
41
5.47k
        json_html_util::dumpHtml(html, *parsed);
42
5.47k
        (void)html;
43
5.47k
    }
44
45
12.6k
    return 0;
46
12.6k
}