• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 "net/third_party/uri_template/uri_template.h"
6 
7 #include <fuzzer/FuzzedDataProvider.h>
8 
9 // Entry point for LibFuzzer.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)10 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
11   FuzzedDataProvider fuzzed_data(data, size);
12   std::string uri_template = fuzzed_data.ConsumeRandomLengthString(256);
13   // Construct a map containing variable names and corresponding values.
14   std::unordered_map<std::string, std::string> parameters;
15   uint8_t num_vars(fuzzed_data.ConsumeIntegral<uint8_t>());
16   for (uint8_t i = 0; i < num_vars; i++) {
17     parameters.emplace(fuzzed_data.ConsumeRandomLengthString(10),
18                        fuzzed_data.ConsumeRandomLengthString(10));
19   }
20   std::string target;
21   uri_template::Expand(uri_template, parameters, &target);
22   return 0;
23 }
24