Chromium Code Reviews| 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 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | |
| 30 const char* char_data = reinterpret_cast<const char*>(data); | |
| 31 std::size_t data_hash = | |
|
aizatsky
2017/03/20 20:14:04
with this approach every input bit change would re
| |
| 32 std::hash<std::string>()(std::string(char_data, size)); | |
| 33 PseudoRandomFilter filter(static_cast<uint32_t>(data_hash)); | |
| 34 TemplateURLParser::Parse(SearchTermsData(), char_data, size, &filter); | |
| 35 return 0; | |
| 36 } | |
| OLD | NEW |