Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

f

  • Loading branch information...
commit f23c066a2ff2643b6d1cd51e7513accaa25219d6 1 parent cad57a9
Matt Corallo authored
Showing with 19 additions and 7 deletions.
  1. +18 −6 src/fuzzer.cpp
  2. +1 −1  src/fuzzer.h
24 src/fuzzer.cpp
View
@@ -8,16 +8,25 @@
#include "net.h"
#include "fuzzer.h"
-#include <openssl/rand.h>
+#include <stdlib.h>
#include <boost/math/distributions/exponential.hpp>
// Return integer from [0...n)
static int
R(int n)
{
- unsigned int buf;
- RAND_pseudo_bytes((unsigned char*) &buf, sizeof(int));
- return buf % n;
+ unsigned int random = rand();
+ unsigned int max_custom_rand = RAND_MAX;
+ while (random > max_custom_rand - ((max_custom_rand+1) % n))
+ {
+ // make sure random values are equally probablistic across all possible return values
+ while (n > max_custom_rand+1)
+ {
+ random = random * RAND_MAX + rand();
+ max_custom_rand = max_custom_rand * RAND_MAX + RAND_MAX;
+ }
+ }
+ return random % n;
}
// Return integer from [0..n),
@@ -38,7 +47,8 @@ static std::vector<unsigned char>
Bytes(int n)
{
std::vector<unsigned char> result;
- RAND_pseudo_bytes(&result[0], n);
+ for (int i = 0; i < n; i++)
+ result[i] = R(256);
return result;
}
@@ -111,8 +121,10 @@ EraseBytes(CDataStream& s, int n)
}
void
-FuzzTransaction(const CTransaction& tx, const uint64_t& fuzzSeed, CDataStream& fuzzedDataRet)
+FuzzTransaction(const CTransaction& tx, const unsigned int& fuzzSeed, CDataStream& fuzzedDataRet)
{
+ srand(fuzzSeed);
+
CTransaction tweaked = tx;
TweakScriptSig(tweaked);
2  src/fuzzer.h
View
@@ -6,7 +6,7 @@
#include "main.h"
-extern void FuzzTransaction(const CTransaction& tx, const uint64_t& fuzzSeed, CDataStream& fuzzedDataRet);
+extern void FuzzTransaction(const CTransaction& tx, const unsigned int& fuzzSeed, CDataStream& fuzzedDataRet);
extern void FuzzRelayTransaction(const CTransaction& tx);
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.