/src/boost_uuid_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/uuid/string_generator.hpp> |
14 | | #include <boost/uuid/name_generator.hpp> |
15 | | #include <boost/uuid/uuid_hash.hpp> |
16 | | #include <boost/uuid/uuid.hpp> |
17 | | #include <boost/uuid/uuid_io.hpp> |
18 | | #include <boost/uuid/nil_generator.hpp> |
19 | | #include <fuzzer/FuzzedDataProvider.h> |
20 | | |
21 | | using namespace std; |
22 | | using namespace boost::uuids; |
23 | | |
24 | 16.0k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size){ |
25 | | |
26 | 16.0k | try{ |
27 | 16.0k | FuzzedDataProvider fdp(Data, Size); |
28 | 16.0k | std::string s = fdp.ConsumeRemainingBytesAsString(); |
29 | | |
30 | 16.0k | string_generator gen_string; |
31 | 16.0k | name_generator_sha1 gen_name(ns::url()); |
32 | 16.0k | hash<uuid> hasher; |
33 | | |
34 | 16.0k | uuid u_string, u_name; |
35 | | |
36 | 16.0k | u_string = gen_string(s); |
37 | 16.0k | u_name = gen_name(s); |
38 | | |
39 | 16.0k | size_t string_hash = hasher(u_string); |
40 | 16.0k | size_t name_hash = hash_value(u_name); |
41 | 16.0k | size_t uuid_hash_value = hasher(boost::uuids::uuid()); |
42 | | |
43 | 16.0k | string out_string = to_string(u_string); |
44 | 16.0k | wstring out_wstring = to_wstring(u_string); |
45 | | |
46 | 16.0k | swap(u_string, u_name); |
47 | 16.0k | } catch(...) { |
48 | 10.6k | } |
49 | | |
50 | 16.0k | return 0; |
51 | 16.0k | } |