/src/boost_regex_pattern_fuzzer.cc
Line | Count | Source (jump to first uncovered line) |
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/regex.hpp> |
14 | | #ifdef DEBUG |
15 | | #include <iostream> |
16 | | #endif |
17 | | #include <string> |
18 | | #include <vector> |
19 | | #include <fuzzer/FuzzedDataProvider.h> |
20 | | |
21 | 187 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
22 | 187 | FuzzedDataProvider fdp(Data, Size); |
23 | | // Currently, we just consume all the fuzzed corpus into the regex pattern |
24 | 187 | std::string regex_string = fdp.ConsumeRemainingBytesAsString(); |
25 | 187 | const uint8_t where_array[] = {0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48,0x48}; |
26 | 187 | std::string random(where_array, where_array + sizeof(where_array)); |
27 | 187 | std::string empty(""); |
28 | 187 | std::string spaces(" "); |
29 | 187 | try { |
30 | 187 | std::vector<std::string> wheres; |
31 | 187 | wheres.push_back(random); |
32 | 187 | wheres.push_back(empty); |
33 | 187 | wheres.push_back(spaces); |
34 | 187 | boost::regex e(regex_string); |
35 | | // We're using multiple texts to be matched. |
36 | | #ifdef DEBUG |
37 | | std::cout << "Regexp string: " << regex_string << "Size: " << regex_string.size() << std::endl; |
38 | | #endif |
39 | | |
40 | 252 | for (const auto& where : wheres) { |
41 | 252 | try { |
42 | 252 | boost::match_results<std::string::const_iterator> what; |
43 | 252 | bool match = boost::regex_match(where, what, e, boost::match_default | boost::match_partial | boost::match_posix | boost::match_any); |
44 | 252 | } catch(...) { |
45 | 0 | } |
46 | | |
47 | 252 | try { |
48 | 252 | boost::match_results<std::string::const_iterator> what; |
49 | 252 | bool match = boost::regex_match(where, what, e, boost::match_default | boost::match_partial | boost::match_perl | boost::match_any); |
50 | 252 | } catch(...) { |
51 | 0 | } |
52 | 252 | } |
53 | 187 | } catch(...) { |
54 | 103 | } |
55 | 187 | return 0; |
56 | 187 | } |