OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 8 #include <random> |
| 9 #include <string> |
| 10 |
| 11 #include "components/search_engines/search_terms_data.h" |
| 12 #include "components/search_engines/template_url.h" |
| 13 #include "components/search_engines/template_url_parser.h" |
| 14 |
| 15 class PseudoRandomFilter : public TemplateURLParser::ParameterFilter { |
| 16 public: |
| 17 PseudoRandomFilter(uint32_t seed) : generator_(seed), pool_(0, 1) {} |
| 18 ~PseudoRandomFilter() override = default; |
| 19 |
| 20 bool KeepParameter(const std::string&, const std::string&) override { |
| 21 return pool_(generator_); |
| 22 } |
| 23 |
| 24 private: |
| 25 std::mt19937 generator_; |
| 26 std::uniform_int_distribution<uint8_t> pool_; |
| 27 }; |
| 28 |
| 29 struct FuzzerFixedParams { |
| 30 uint32_t seed_; |
| 31 }; |
| 32 |
| 33 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 34 if (size < sizeof(FuzzerFixedParams)) { |
| 35 return 0; |
| 36 } |
| 37 const FuzzerFixedParams* params = |
| 38 reinterpret_cast<const FuzzerFixedParams*>(data); |
| 39 size -= sizeof(FuzzerFixedParams); |
| 40 const char* char_data = reinterpret_cast<const char*>(params + 1); |
| 41 PseudoRandomFilter filter(params->seed_); |
| 42 TemplateURLParser::Parse(SearchTermsData(), char_data, size, &filter); |
| 43 return 0; |
| 44 } |
OLD | NEW |