xref: /aosp_15_r20/external/cronet/testing/libfuzzer/fuzzers/string_compare_fuzzer.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2024 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 <cstdlib>
6 #include <iostream>
7 #include <string>
8 
9 // Very simple fuzzer to allow us to (manually) test that string comparison
10 // instrumentation is working. If so, this should almost immediately crash,
11 // otherwise it will run almost forever because there's no real chance of
12 // hitting upon 'fish' by accident.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
14   std::string the_string(reinterpret_cast<const char*>(data), size);
15 
16   if (the_string == "fish") {
17     std::cout << "Found fish\n";
18     exit(1);
19   }
20 
21   return 0;
22 }
23