• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/strings/escape.h"
6 
7 #include <string_view>
8 
9 // Prevent the optimizer from optimizing away a function call by "using" the
10 // result.
11 //
12 // TODO(crbug.com/40243629): Replace this with a more general solution.
UseResult(const std::string & input)13 void UseResult(const std::string& input) {
14   volatile char c;
15   if (input.length() > 0)
16     c = input[0];
17   (void)c;
18 }
19 
20 // Entry point for LibFuzzer.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
22   std::string_view data_string(reinterpret_cast<const char*>(data), size);
23 
24   UseResult(base::EscapeQueryParamValue(data_string, /*use_plus=*/false));
25   UseResult(base::EscapeQueryParamValue(data_string, /*use_plus=*/true));
26 
27   return 0;
28 }
29