/src/tomlplusplus/fuzzing/toml_fuzzer.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include <cstdint> |
2 | | #include <fuzzer/FuzzedDataProvider.h> |
3 | | |
4 | | #include <toml++/toml.hpp> |
5 | | |
6 | | enum class SerializationTest |
7 | | { |
8 | | NONE = 0, |
9 | | JSON, |
10 | | YAML, |
11 | | TOML, |
12 | | kMaxValue = TOML |
13 | | }; |
14 | | |
15 | | extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, const std::size_t size) |
16 | 6.85k | { |
17 | 6.85k | FuzzedDataProvider fdp{data, size}; |
18 | 6.85k | try |
19 | 6.85k | { |
20 | 6.85k | const toml::table tbl = toml::parse(fdp.ConsumeRandomLengthString()); |
21 | | |
22 | 6.85k | switch (fdp.ConsumeEnum<SerializationTest>()) |
23 | 6.85k | { |
24 | 9 | case SerializationTest::JSON: |
25 | 9 | static_cast<void>(toml::json_formatter{tbl}); |
26 | 9 | break; |
27 | 12 | case SerializationTest::YAML: |
28 | 12 | static_cast<void>(toml::yaml_formatter{tbl}); |
29 | 12 | break; |
30 | 13 | case SerializationTest::TOML: |
31 | 13 | static_cast<void>(toml::toml_formatter{tbl}); |
32 | 3.54k | default: |
33 | 3.54k | break; |
34 | 6.85k | } |
35 | 6.85k | } |
36 | 6.85k | catch (const toml::parse_error&) |
37 | 6.85k | { |
38 | 3.28k | return -1; |
39 | 3.28k | } |
40 | 3.56k | return 0; |
41 | 6.85k | } |