Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <random> | 8 #include <random> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | |
| 12 #include "base/i18n/icu_util.h" | |
| 11 #include "components/search_engines/search_terms_data.h" | 13 #include "components/search_engines/search_terms_data.h" |
| 12 #include "components/search_engines/template_url.h" | 14 #include "components/search_engines/template_url.h" |
| 13 #include "components/search_engines/template_url_parser.h" | 15 #include "components/search_engines/template_url_parser.h" |
| 14 | 16 |
| 15 class PseudoRandomFilter : public TemplateURLParser::ParameterFilter { | 17 class PseudoRandomFilter : public TemplateURLParser::ParameterFilter { |
| 16 public: | 18 public: |
| 17 PseudoRandomFilter(uint32_t seed) : generator_(seed), pool_(0, 1) {} | 19 PseudoRandomFilter(uint32_t seed) : generator_(seed), pool_(0, 1) {} |
| 18 ~PseudoRandomFilter() override = default; | 20 ~PseudoRandomFilter() override = default; |
| 19 | 21 |
| 20 bool KeepParameter(const std::string&, const std::string&) override { | 22 bool KeepParameter(const std::string&, const std::string&) override { |
| 21 return pool_(generator_); | 23 return pool_(generator_); |
| 22 } | 24 } |
| 23 | 25 |
| 24 private: | 26 private: |
| 25 std::mt19937 generator_; | 27 std::mt19937 generator_; |
| 26 std::uniform_int_distribution<uint8_t> pool_; | 28 std::uniform_int_distribution<uint8_t> pool_; |
| 27 }; | 29 }; |
| 28 | 30 |
| 29 struct FuzzerFixedParams { | 31 struct FuzzerFixedParams { |
| 30 uint32_t seed_; | 32 uint32_t seed_; |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 35 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 34 if (size < sizeof(FuzzerFixedParams)) { | 36 if (size < sizeof(FuzzerFixedParams)) { |
| 35 return 0; | 37 return 0; |
| 36 } | 38 } |
| 39 base::AtExitManager at_exit_manager; // used by ICU integration. | |
| 40 base::i18n::InitializeICU(); | |
|
jochen (gone - plz use gerrit)
2017/04/18 07:08:57
for posterity, we can't initialize ICU once per fu
| |
| 37 const FuzzerFixedParams* params = | 41 const FuzzerFixedParams* params = |
| 38 reinterpret_cast<const FuzzerFixedParams*>(data); | 42 reinterpret_cast<const FuzzerFixedParams*>(data); |
| 39 size -= sizeof(FuzzerFixedParams); | 43 size -= sizeof(FuzzerFixedParams); |
| 40 const char* char_data = reinterpret_cast<const char*>(params + 1); | 44 const char* char_data = reinterpret_cast<const char*>(params + 1); |
| 41 PseudoRandomFilter filter(params->seed_); | 45 PseudoRandomFilter filter(params->seed_); |
| 42 TemplateURLParser::Parse(SearchTermsData(), char_data, size, &filter); | 46 TemplateURLParser::Parse(SearchTermsData(), char_data, size, &filter); |
| 43 return 0; | 47 return 0; |
| 44 } | 48 } |
| OLD | NEW |