/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 | 4.85k | { |
27 | 4.85k | if (size == 0) |
28 | 0 | { |
29 | 0 | return 0; |
30 | 0 | } |
31 | | |
32 | 4.85k | std::string input(reinterpret_cast<const char*>(data), size); |
33 | | |
34 | | // Parse JSON using bmcweb's own SAX parser (with depth/width limits) |
35 | 4.85k | std::optional<nlohmann::json> parsed = parseStringAsJson(input); |
36 | | |
37 | 4.85k | if (parsed) |
38 | 2.56k | { |
39 | | // Exercise the HTML serializer on successfully parsed JSON |
40 | 2.56k | std::string html; |
41 | 2.56k | json_html_util::dumpHtml(html, *parsed); |
42 | 2.56k | (void)html; |
43 | 2.56k | } |
44 | | |
45 | 4.85k | return 0; |
46 | 4.85k | } |