Changeset View
Changeset View
Standalone View
Standalone View
src/test/test_bitcoin_fuzzy.cpp
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | static bool read_stdin(std::vector<char> &data) { | ||||
while ((length = read(STDIN_FILENO, buffer, 1024)) > 0) { | while ((length = read(STDIN_FILENO, buffer, 1024)) > 0) { | ||||
data.insert(data.end(), buffer, buffer + length); | data.insert(data.end(), buffer, buffer + length); | ||||
if (data.size() > (1 << 20)) return false; | if (data.size() > (1 << 20)) return false; | ||||
} | } | ||||
return length == 0; | return length == 0; | ||||
} | } | ||||
int main(int argc, char **argv) { | int do_fuzz() { | ||||
ECCVerifyHandle globalVerifyHandle; | |||||
std::vector<char> buffer; | std::vector<char> buffer; | ||||
if (!read_stdin(buffer)) return 0; | if (!read_stdin(buffer)) return 0; | ||||
if (buffer.size() < sizeof(uint32_t)) return 0; | if (buffer.size() < sizeof(uint32_t)) return 0; | ||||
uint32_t test_id = 0xffffffff; | uint32_t test_id = 0xffffffff; | ||||
memcpy(&test_id, buffer.data(), sizeof(uint32_t)); | memcpy(&test_id, buffer.data(), sizeof(uint32_t)); | ||||
buffer.erase(buffer.begin(), buffer.begin() + sizeof(uint32_t)); | buffer.erase(buffer.begin(), buffer.begin() + sizeof(uint32_t)); | ||||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | switch (test_id) { | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
return 0; | return 0; | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
int main(int argc, char **argv) { | |||||
ECCVerifyHandle globalVerifyHandle; | |||||
#ifdef __AFL_INIT | |||||
// Enable AFL deferred forkserver mode. Requires compilation using | |||||
// afl-clang-fast++. See fuzzing.md for details. | |||||
__AFL_INIT(); | |||||
#endif | |||||
#ifdef __AFL_LOOP | |||||
// Enable AFL persistent mode. Requires compilation using afl-clang-fast++. | |||||
// See fuzzing.md for details. | |||||
while (__AFL_LOOP(1000)) { | |||||
do_fuzz(); | |||||
} | |||||
return 0; | |||||
#else | |||||
return do_fuzz(); | |||||
#endif | |||||
} |