File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -1894,3 +1894,38 @@ uint64 CNode::GetTotalBytesSent()
1894
1894
LOCK (cs_totalBytesSent);
1895
1895
return nTotalBytesSent;
1896
1896
}
1897
+
1898
+ void CNode::Fuzz (int nChance)
1899
+ {
1900
+ if (!fSuccessfullyConnected ) return ; // Don't fuzz initial handshake
1901
+ if (GetRand (nChance) != 0 ) return ; // Fuzz 1 of every nChance messages
1902
+
1903
+ switch (GetRand (3 ))
1904
+ {
1905
+ case 0 :
1906
+ // xor a random byte with a random value:
1907
+ if (!ssSend.empty ()) {
1908
+ CDataStream::size_type pos = GetRand (ssSend.size ());
1909
+ ssSend[pos] ^= (unsigned char )(GetRand (256 ));
1910
+ }
1911
+ break ;
1912
+ case 1 :
1913
+ // delete a random byte:
1914
+ if (!ssSend.empty ()) {
1915
+ CDataStream::size_type pos = GetRand (ssSend.size ());
1916
+ ssSend.erase (ssSend.begin ()+pos);
1917
+ }
1918
+ break ;
1919
+ case 2 :
1920
+ // insert a random byte at a random position
1921
+ {
1922
+ CDataStream::size_type pos = GetRand (ssSend.size ());
1923
+ char ch = (char )GetRand (256 );
1924
+ ssSend.insert (ssSend.begin ()+pos, ch);
1925
+ }
1926
+ break ;
1927
+ }
1928
+ // Chance of more than one change half the time:
1929
+ // (more changes exponentially less likely):
1930
+ Fuzz (2 );
1931
+ }
Original file line number Diff line number Diff line change @@ -218,6 +218,9 @@ class CNode
218
218
static CCriticalSection cs_setBanned;
219
219
int nMisbehavior;
220
220
221
+ // Basic fuzz-testing
222
+ void Fuzz (int nChance); // modifies ssSend
223
+
221
224
public:
222
225
uint256 hashContinue;
223
226
CBlockIndex* pindexLastGetBlocksBegin;
@@ -434,12 +437,17 @@ class CNode
434
437
// TODO: Document the precondition of this function. Is cs_vSend locked?
435
438
void EndMessage () UNLOCK_FUNCTION(cs_vSend)
436
439
{
437
- if (mapArgs.count (" -dropmessagestest" ) && GetRand (atoi (mapArgs[" -dropmessagestest" ])) == 0 )
440
+ // The -*messagestest options are intentionally not documented in the help message,
441
+ // since they are only used during development to debug the networking code and are
442
+ // not intended for end-users.
443
+ if (mapArgs.count (" -dropmessagestest" ) && GetRand (GetArg (" -dropmessagestest" , 2 )) == 0 )
438
444
{
439
445
LogPrint (" net" , " dropmessages DROPPING SEND MESSAGE\n " );
440
446
AbortMessage ();
441
447
return ;
442
448
}
449
+ if (mapArgs.count (" -fuzzmessagestest" ))
450
+ Fuzz (GetArg (" -fuzzmessagestest" , 10 ));
443
451
444
452
if (ssSend.size () == 0 )
445
453
return ;
You can’t perform that action at this time.
0 commit comments