Skip to content

Commit

Permalink
Update FuzzerStunPacket.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Feb 19, 2024
1 parent 033cfec commit 1c36427
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions worker/fuzzer/src/RTC/FuzzerStunPacket.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "RTC/FuzzerStunPacket.hpp"
#include "RTC/StunPacket.hpp"

static constexpr size_t StunSerializeBufferSize{ 65536 };
thread_local static uint8_t StunSerializeBuffer[StunSerializeBufferSize];

void Fuzzer::RTC::StunPacket::Fuzz(const uint8_t* data, size_t len)
{
if (!::RTC::StunPacket::IsStun(data, len))
Expand All @@ -21,6 +24,7 @@ void Fuzzer::RTC::StunPacket::Fuzz(const uint8_t* data, size_t len)
packet->GetData();
packet->GetSize();
packet->SetUsername("foo", 3);
packet->SetPassword("lalala");
packet->SetPriority(123);
packet->SetIceControlling(123);
packet->SetIceControlled(123);
Expand All @@ -37,13 +41,21 @@ void Fuzzer::RTC::StunPacket::Fuzz(const uint8_t* data, size_t len)
packet->GetErrorCode();
packet->HasMessageIntegrity();
packet->HasFingerprint();
packet->CheckAuthentication("foo", "bar");
// TODO: packet->CreateSuccessResponse(); // This cannot be easily tested.
// TODO: packet->CreateErrorResponse(); // This cannot be easily tested.
packet->Authenticate("lalala");
// TODO: Cannot test Serialize() because we don't know the exact required
// buffer size (setters above may change the total size).
// TODO: packet->Serialize();
packet->CheckAuthentication("foo", "bar", "xxx");

if (packet->GetClass() == ::RTC::StunPacket::Class::REQUEST)
{
auto* successResponse = packet->CreateSuccessResponse();
auto* errorResponse = packet->CreateErrorResponse(444);

delete successResponse;
delete errorResponse;
}

if (len < StunSerializeBufferSize - 1000)
{
packet->Serialize(StunSerializeBuffer);
}

delete packet;
}

0 comments on commit 1c36427

Please sign in to comment.