/src/boost_graph_graphviz_fuzzer.cc
Line | Count | Source |
1 | | /* Copyright 2024 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 | | // The ideal place for this fuzz target is the boost repository. |
13 | | #include <boost/graph/adjacency_list.hpp> |
14 | | #include <boost/graph/graphviz.hpp> |
15 | | #include <boost/property_map/dynamic_property_map.hpp> |
16 | | #include <boost/exception/exception.hpp> |
17 | | #include <boost/exception/diagnostic_information.hpp> |
18 | | #ifdef DEBUG |
19 | | #include <iostream> |
20 | | #endif |
21 | | #include <string> |
22 | | #include <fuzzer/FuzzedDataProvider.h> |
23 | | |
24 | | struct DotVertex { |
25 | | std::string name; |
26 | | std::string label; |
27 | | int peripheries; |
28 | | }; |
29 | | |
30 | | struct DotEdge { |
31 | | std::string label; |
32 | | }; |
33 | | |
34 | | typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, |
35 | | DotVertex, DotEdge> graph_t; |
36 | | |
37 | | using namespace boost; |
38 | | |
39 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
40 | 16.0k | { |
41 | 16.0k | FuzzedDataProvider fdp(data, size); |
42 | 16.0k | try |
43 | 16.0k | { |
44 | 16.0k | graph_t graphviz; |
45 | 16.0k | boost::dynamic_properties dp(boost::ignore_other_properties); |
46 | 16.0k | dp.property("node_id", boost::get(&DotVertex::name, graphviz)); |
47 | 16.0k | read_graphviz(fdp.ConsumeRemainingBytesAsString(), graphviz, dp); |
48 | 16.0k | auto viter = make_iterator_range(vertices(graphviz)); |
49 | | #ifdef DEBUG |
50 | | for (auto v : viter) { |
51 | | std::cout << v << " "; |
52 | | } |
53 | | #endif |
54 | 16.0k | } catch(...) { |
55 | 10.6k | } |
56 | 16.0k | return 0; |
57 | 16.0k | } |