xref: /aosp_15_r20/external/cronet/base/strings/escape_fuzzer.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 // Prevent the optimizer from optimizing away a function call by "using" the
8 // result.
9 //
10 // TODO(crbug.com/1377534): Replace this with a more general solution.
UseResult(const std::string & input)11 void UseResult(const std::string& input) {
12   volatile char c;
13   if (input.length() > 0)
14     c = input[0];
15   (void)c;
16 }
17 
18 // Entry point for LibFuzzer.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)19 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
20   base::StringPiece data_string(reinterpret_cast<const char*>(data), size);
21 
22   UseResult(base::EscapeQueryParamValue(data_string, /*use_plus=*/false));
23   UseResult(base::EscapeQueryParamValue(data_string, /*use_plus=*/true));
24 
25   return 0;
26 }
27