summaryrefslogtreecommitdiffstats
path: root/chromium/base/strings/escape_fuzzer.cc
blob: 4af8525d79cdf93fdbf5dc2601883b0701f031aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/strings/escape.h"

// Prevent the optimizer from optimizing away a function call by "using" the
// result.
//
// TODO(crbug.com/1377534): Replace this with a more general solution.
void UseResult(const std::string& input) {
  volatile char c;
  if (input.length() > 0)
    c = input[0];
  (void)c;
}

// Entry point for LibFuzzer.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  base::StringPiece data_string(reinterpret_cast<const char*>(data), size);

  UseResult(base::EscapeQueryParamValue(data_string, /*use_plus=*/false));
  UseResult(base::EscapeQueryParamValue(data_string, /*use_plus=*/true));

  return 0;
}