-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathFuzzerStateCookie.cpp
More file actions
76 lines (60 loc) · 2.38 KB
/
FuzzerStateCookie.cpp
File metadata and controls
76 lines (60 loc) · 2.38 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "RTC/SCTP/association/FuzzerStateCookie.hpp"
#include "Utils.hpp"
#include "RTC/SCTP/association/StateCookie.hpp"
#include <cstdlib> // std::malloc(), std::free()
#include <cstring> // std::memcpy()
thread_local static uint8_t StateCookieSerializeBuffer[65536];
thread_local static uint8_t StateCookieCloneBuffer[65536];
void Fuzzer::RTC::SCTP::StateCookie::Fuzz(const uint8_t* data, size_t len)
{
auto* clonedData = static_cast<uint8_t*>(std::malloc(len));
std::memcpy(clonedData, data, len);
// We need to force `data` to be a StateCookie since it's too hard that random
// data matches it.
if (len > ::RTC::SCTP::StateCookie::StateCookieLength)
{
len = ::Utils::Crypto::GetRandomUInt32(
::RTC::SCTP::StateCookie::StateCookieLength, ::RTC::SCTP::StateCookie::StateCookieLength + 10);
if (len < ::RTC::SCTP::StateCookie::StateCookieLength + 5)
{
::Utils::Byte::Set8Bytes(clonedData, 0, ::RTC::SCTP::StateCookie::Magic1);
::Utils::Byte::Set2Bytes(
clonedData,
::RTC::SCTP::StateCookie::NegotiatedCapabilitiesOffset,
::RTC::SCTP::StateCookie::Magic2);
}
}
::RTC::SCTP::StateCookie* stateCookie = ::RTC::SCTP::StateCookie::Parse(clonedData, len);
if (!stateCookie)
{
std::free(clonedData);
return;
}
stateCookie->GetLocalVerificationTag();
stateCookie->GetRemoteVerificationTag();
stateCookie->GetLocalInitialTsn();
stateCookie->GetRemoteInitialTsn();
stateCookie->GetRemoteAdvertisedReceiverWindowCredit();
stateCookie->GetTieTag();
stateCookie->GetNegotiatedCapabilities();
stateCookie->Serialize(StateCookieSerializeBuffer, len);
stateCookie->GetLocalVerificationTag();
stateCookie->GetRemoteVerificationTag();
stateCookie->GetLocalInitialTsn();
stateCookie->GetRemoteInitialTsn();
stateCookie->GetRemoteAdvertisedReceiverWindowCredit();
stateCookie->GetTieTag();
stateCookie->GetNegotiatedCapabilities();
auto* clonedStateCookie = stateCookie->Clone(StateCookieCloneBuffer, len);
delete stateCookie;
clonedStateCookie->GetLocalVerificationTag();
clonedStateCookie->GetRemoteVerificationTag();
clonedStateCookie->GetLocalInitialTsn();
clonedStateCookie->GetRemoteInitialTsn();
clonedStateCookie->GetRemoteAdvertisedReceiverWindowCredit();
clonedStateCookie->GetTieTag();
clonedStateCookie->GetNegotiatedCapabilities();
clonedStateCookie->Serialize(StateCookieSerializeBuffer, len);
std::free(clonedData);
delete clonedStateCookie;
}