Added basic fuzzing to the monolith, see ticket #4155

This commit is contained in:
zebambam 2019-10-15 00:00:21 +00:00
parent ffb8e6747b
commit 7e8b18e480
3 changed files with 25 additions and 1 deletions

View File

@ -186,7 +186,10 @@ bool AppInit(int argc, char* argv[])
return fRet;
}
#include "fuzz.h"
#ifdef ZCASH_FUZZ
#include "fuzz.cpp"
#else
int main(int argc, char* argv[])
{
SetupEnvironment();
@ -196,3 +199,4 @@ int main(int argc, char* argv[])
return (AppInit(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE);
}
#endif

18
src/fuzz.cpp Normal file
View File

@ -0,0 +1,18 @@
extern bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx);
bool fuzz_DecodeHexTxFunction (const std::string& strHexTx) {
CTransaction tx;
return DecodeHexTx(tx, strHexTx);
}
int fuzz_DecodeHexTx (int argc, char *argv[]) {
std::ifstream t(argv[1]);
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
if (fuzz_DecodeHexTxFunction (str)) { fprintf(stdout, "Decoded hex string") ; return 0; }
else { fprintf(stderr, "Could not decode hex string") ; return -1; }
}
int main (int argc, char *argv[]) { return ZCASH_FUZZER_MAIN(argc, argv); }
#warning BUILDING A FUZZER, NOT THE REAL MAIN

2
src/fuzz.h Normal file
View File

@ -0,0 +1,2 @@
//#define ZCASH_FUZZ
#define ZCASH_FUZZER_MAIN fuzz_DecodeHexTx