PIVX Core  5.6.99
P2P Digital Currency
fuzz.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
4 
5 #include "test/fuzz/fuzz.h"
6 
7 #include <unistd.h>
8 
9 #include "chainparams.h"
10 #include "pubkey.h"
11 
12 
13 static bool read_stdin(std::vector<uint8_t>& data)
14 {
15  uint8_t buffer[1024];
16  ssize_t length = 0;
17  while ((length = read(STDIN_FILENO, buffer, 1024)) > 0) {
18  data.insert(data.end(), buffer, buffer + length);
19 
20  if (data.size() > (1 << 20)) return false;
21  }
22  return length == 0;
23 }
24 
25 static void initialize()
26 {
27  const static auto verify_handle = std::make_unique<ECCVerifyHandle>();
29 }
30 
31 // This function is used by libFuzzer
32 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
33 {
34  test_one_input(std::vector<uint8_t>(data, data + size));
35  return 0;
36 }
37 
38 // This function is used by libFuzzer
39 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
40 {
41  initialize();
42  return 0;
43 }
44 
45 // Disabled under WIN32 due to clash with Cygwin's WinMain.
46 #ifndef WIN32
47 // Declare main(...) "weak" to allow for libFuzzer linking. libFuzzer provides
48 // the main(...) function.
50 #endif
51 int main(int argc, char **argv)
52 {
53  initialize();
54 #ifdef __AFL_INIT
55  // Enable AFL deferred forkserver mode. Requires compilation using
56  // afl-clang-fast++. See fuzzing.md for details.
57  __AFL_INIT();
58 #endif
59 
60 #ifdef __AFL_LOOP
61  // Enable AFL persistent mode. Requires compilation using afl-clang-fast++.
62  // See fuzzing.md for details.
63  while (__AFL_LOOP(1000)) {
64  std::vector<uint8_t> buffer;
65  if (!read_stdin(buffer)) {
66  continue;
67  }
69  }
70 #else
71  std::vector<uint8_t> buffer;
72  if (!read_stdin(buffer)) {
73  return 0;
74  }
76 #endif
77  return 0;
78 }
int main(int argc, char **argv)
Definition: bench_pivx.cpp:29
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
static const std::string MAIN
Chain name strings.
std::vector< uint8_t > buffer
Definition: fuzz.cpp:71
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition: fuzz.cpp:32
int LLVMFuzzerInitialize(int *argc, char ***argv)
Definition: fuzz.cpp:39
test_one_input(buffer)
__attribute__((weak)) int main(int argc
char ** argv
Definition: fuzz.cpp:52