1 // Copyright 2022 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <fuzzer/FuzzedDataProvider.h> 6 #include <stdint.h> 7 8 #include <set> 9 #include <string> 10 #include <vector> 11 12 #include "base/substring_set_matcher/matcher_string_pattern.h" 13 #include "base/substring_set_matcher/substring_set_matcher.h" 14 15 namespace base { 16 LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)17extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 18 FuzzedDataProvider provider(data, size); 19 20 std::vector<MatcherStringPattern> patterns; 21 std::set<std::string> pattern_set; 22 for (;;) { 23 std::string pattern = provider.ConsumeRandomLengthString(); 24 if (pattern.empty() || pattern_set.count(pattern)) 25 break; 26 patterns.emplace_back(pattern, patterns.size()); 27 pattern_set.insert(pattern); 28 } 29 30 SubstringSetMatcher matcher; 31 if (matcher.Build(patterns)) { 32 std::set<MatcherStringPattern::ID> matches; 33 matcher.Match(provider.ConsumeRandomLengthString(), &matches); 34 } 35 36 return 0; 37 } 38 39 } // namespace base 40