-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathFuzzerRateCalculator.cpp
More file actions
47 lines (36 loc) · 1.02 KB
/
FuzzerRateCalculator.cpp
File metadata and controls
47 lines (36 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "RTC/FuzzerRateCalculator.hpp"
#include "DepLibUV.hpp"
#include "Utils.hpp"
#include "RTC/Consts.hpp"
#include "RTC/RateCalculator.hpp"
static ::RTC::RateCalculator rateCalculator;
static uint64_t nowMs;
// This Init() function must be declared static, otherwise linking will fail if
// another source file defines same non static Init() function.
static int Init();
void Fuzzer::RTC::RateCalculator::Fuzz(const uint8_t* data, size_t len)
{
// Trick to initialize our stuff just once.
static int unused = Init();
// Avoid [-Wunused-variable].
(void)unused;
// We need at least 2 bytes of |data|.
if (len < 2)
{
return;
}
auto size = static_cast<size_t>(
Utils::Crypto::GetRandomUInt32(0u, static_cast<uint32_t>(::RTC::Consts::MtuSize)));
nowMs += Utils::Crypto::GetRandomUInt32(0u, 1000u);
rateCalculator.Update(size, nowMs);
// Only get rate from time to time.
if (Utils::Byte::Get2Bytes(data, 0) % 100 == 0)
{
rateCalculator.GetRate(nowMs);
}
}
int Init()
{
nowMs = DepLibUV::GetTimeMs();
return 0;
}