提交 638103af authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

worker tests and fuzzer: refactor sources hierarchy

上级 8cf0aa23
......@@ -157,7 +157,7 @@ Replace the references of the current directory by the keywork 'PATH':
$ sed -i "s|$PWD|PATH|g" compile_commands.json
```
Edit the file and remove the entry related to Utils/IP.cpp compilation unit, which is automatically created and does not follow the clang-tidy rules.
Edit the file and remove the entry related to `Utils/IP.cpp` compilation unit, which is automatically created and does not follow the clang-tidy rules.
*NOTE:* It just works on Linux and OSX.
......
......@@ -17,7 +17,7 @@ Once we have built the `mediasoup-worker-fuzzer` target in a Linux environment w
The `fuzzer/corpora` directory has corpus directories taken from Chromium projects. They should be use to feed fuzzer with appropriate input.
However, given how `libFuzzer` works, the first directory given as command line parameter is not just used for reading corpus files, but also to store newly generated ones. So, it's recommended to pass `fuzzer/new-corpus` as first directory. Such a directory is gitignored (for now).
However, given how `libFuzzer` [works](http://llvm.org/docs/LibFuzzer.html#options), the first directory given as command line parameter is not just used for reading corpus files, but also to store newly generated ones. So, it's recommended to pass `fuzzer/new-corpus` as first directory. Such a directory is gitignored (for now).
## Crash reports
......@@ -40,7 +40,7 @@ For memory leak detection enable the following environment variable:
* `LSAN_OPTIONS=verbosity=1:log_threads=1`
The `fuzzer/fuzzer.cpp` file reads some custom environment variables to decide which kind of fuzzing perform:
The mediasoup-worker fuzzer reads some custom environment variables to decide which kind of fuzzing perform:
* `MS_FUZZ_STUN=1`: Do STUN fuzzing.
* `MS_FUZZ_RTP=1`: Do RTP fuzzing.
......
#ifndef MS_FUZZER_RTC_RTP_PACKET_HPP
#define MS_FUZZER_RTC_RTP_PACKET_HPP
#include "common.hpp"
namespace Fuzzer
{
namespace RTC
{
namespace RtpPacket
{
void Fuzz(const uint8_t* data, size_t len);
}
}
}
#endif
#ifndef MS_FUZZER_RTC_STUN_MESSAGE_HPP
#define MS_FUZZER_RTC_STUN_MESSAGE_HPP
#include "common.hpp"
namespace Fuzzer
{
namespace RTC
{
namespace StunMessage
{
void Fuzz(const uint8_t* data, size_t len);
}
}
}
#endif
#ifndef MS_FUZZER_RTC_RTCP_PACKET_HPP
#define MS_FUZZER_RTC_RTCP_PACKET_HPP
#include "common.hpp"
namespace Fuzzer
{
namespace RTC
{
namespace RTCP
{
namespace Packet
{
void Fuzz(const uint8_t* data, size_t len);
}
}
}
}
#endif
#ifndef MS_FUZZERS_HPP
#define MS_FUZZERS_HPP
#include "common.hpp"
namespace fuzzers
{
void fuzzStun(const uint8_t* data, size_t len);
void fuzzRtp(const uint8_t* data, size_t len);
void fuzzRtcp(const uint8_t* data, size_t len);
}
#endif
#include "RTC/FuzzerRtpPacket.hpp"
#include "RTC/RtpPacket.hpp"
#include <cstring> // std::memory()
void Fuzzer::RTC::RtpPacket::Fuzz(const uint8_t* data, size_t len)
{
if (!::RTC::RtpPacket::IsRtp(data, len))
return;
// We need to clone the given data into a separate buffer because setters
// below will try to write into packet memory.
uint8_t data2[len];
std::memcpy(data2, data, len);
::RTC::RtpPacket* packet = ::RTC::RtpPacket::Parse(data2, len);
if (!packet)
return;
packet->Dump();
packet->GetData();
packet->GetSize();
packet->GetPayloadType();
packet->SetPayloadType(100);
packet->HasMarker();
packet->SetMarker(true);
packet->SetPayloadPaddingFlag(true);
packet->GetSequenceNumber();
packet->SetSequenceNumber(12345);
packet->GetTimestamp();
packet->SetTimestamp(8888);
packet->GetSsrc();
packet->SetSsrc(666);
packet->HasExtensionHeader();
packet->GetExtensionHeaderId();
packet->GetExtensionHeaderLength();
packet->GetExtensionHeaderValue();
// TODO: packet->MangleExtensionHeaderIds();
packet->HasOneByteExtensions();
packet->HasTwoBytesExtensions();
// TODO: packet->AddExtensionMapping();
// TODO: packet->GetExtension();
// TODO: packet->ReadAudioLevel();
// TODO: packet->ReadAbsSendTime();
// TODO: packet->ReadMid();
// TODO: packet->ReadRid();
packet->GetPayload();
packet->GetPayloadLength();
packet->GetPayloadPadding();
packet->IsKeyFrame();
{
uint8_t buffer[len];
auto* clonedPacket = packet->Clone(buffer);
delete clonedPacket;
}
// TODO: packet->RtxEncode(); // This cannot be tested this way.
// TODO: packet->RtxDecode(); // This cannot be tested this way.
// TODO: packet->SetPayloadDescriptorHandler();
// TODO: packet->EncodePayload();
// TODO: packet->EncodePayload();
// TODO: packet->ShiftPayload();
delete packet;
}
#include "RTC/FuzzerStunMessage.hpp"
#include "RTC/StunMessage.hpp"
void Fuzzer::RTC::StunMessage::Fuzz(const uint8_t* data, size_t len)
{
if (!::RTC::StunMessage::IsStun(data, len))
return;
::RTC::StunMessage* msg = ::RTC::StunMessage::Parse(data, len);
if (!msg)
return;
msg->Dump();
msg->GetClass();
msg->GetMethod();
msg->GetData();
msg->GetSize();
msg->SetUsername("foo", 3);
msg->SetPriority(123);
msg->SetIceControlling(123);
msg->SetIceControlled(123);
msg->SetUseCandidate();
// TODO: msg->SetXorMappedAddress();
msg->SetErrorCode(666);
// TODO: msg->SetMessageIntegrity();
msg->SetFingerprint();
msg->GetUsername();
msg->GetPriority();
msg->GetIceControlling();
msg->GetIceControlled();
msg->HasUseCandidate();
msg->GetErrorCode();
msg->HasMessageIntegrity();
msg->HasFingerprint();
msg->CheckAuthentication("foo", "bar");
// TODO: msg->CreateSuccessResponse(); // This cannot be easily tested.
// TODO: msg->CreateErrorResponse(); // This cannot be easily tested.
msg->Authenticate("lalala");
// TODO: Cannot test Serialize() because we don't know the exact required
// buffer size (setters above may change the total size).
// TODO: msg->Serialize();
delete msg;
}
#include "RTC/RTCP/FuzzerPacket.hpp"
#include "RTC/RTCP/Packet.hpp"
void Fuzzer::RTC::RTCP::Packet::Fuzz(const uint8_t* data, size_t len)
{
if (!::RTC::RTCP::Packet::IsRtcp(data, len))
return;
::RTC::RTCP::Packet* packet = ::RTC::RTCP::Packet::Parse(data, len);
if (!packet)
return;
// TODO: Add more checks here.
while (packet != nullptr)
{
auto* previousPacket = packet;
packet = packet->GetNext();
delete previousPacket;
}
}
#include "fuzzers.hpp"
#include "RTC/RTCP/Packet.hpp"
using namespace RTC;
namespace fuzzers
{
void fuzzRtcp(const uint8_t* data, size_t len)
{
if (!RTCP::Packet::IsRtcp(data, len))
return;
RTCP::Packet* packet = RTCP::Packet::Parse(data, len);
if (!packet)
return;
// TODO: Add more checks here.
while (packet != nullptr)
{
auto* previousPacket = packet;
packet = packet->GetNext();
delete previousPacket;
}
}
}
#include "fuzzers.hpp"
#include "RTC/RtpPacket.hpp"
#include <cstring> // std::memory()
using namespace RTC;
namespace fuzzers
{
void fuzzRtp(const uint8_t* data, size_t len)
{
if (!RtpPacket::IsRtp(data, len))
return;
// We need to clone the given data into a separate buffer because setters
// below will try to write into packet memory.
uint8_t data2[len];
std::memcpy(data2, data, len);
RtpPacket* packet = RtpPacket::Parse(data2, len);
if (!packet)
return;
packet->Dump();
packet->GetData();
packet->GetSize();
packet->GetPayloadType();
packet->SetPayloadType(100);
packet->HasMarker();
packet->SetMarker(true);
packet->SetPayloadPaddingFlag(true);
packet->GetSequenceNumber();
packet->SetSequenceNumber(12345);
packet->GetTimestamp();
packet->SetTimestamp(8888);
packet->GetSsrc();
packet->SetSsrc(666);
packet->HasExtensionHeader();
packet->GetExtensionHeaderId();
packet->GetExtensionHeaderLength();
packet->GetExtensionHeaderValue();
// TODO: packet->MangleExtensionHeaderIds();
packet->HasOneByteExtensions();
packet->HasTwoBytesExtensions();
// TODO: packet->AddExtensionMapping();
// TODO: packet->GetExtension();
// TODO: packet->ReadAudioLevel();
// TODO: packet->ReadAbsSendTime();
// TODO: packet->ReadMid();
// TODO: packet->ReadRid();
packet->GetPayload();
packet->GetPayloadLength();
packet->GetPayloadPadding();
packet->IsKeyFrame();
{
uint8_t buffer[len];
auto* clonedPacket = packet->Clone(buffer);
delete clonedPacket;
}
// TODO: packet->RtxEncode(); // This cannot be tested this way.
// TODO: packet->RtxDecode(); // This cannot be tested this way.
// TODO: packet->SetPayloadDescriptorHandler();
// TODO: packet->EncodePayload();
// TODO: packet->EncodePayload();
// TODO: packet->ShiftPayload();
delete packet;
}
}
#include "fuzzers.hpp"
#include "RTC/StunMessage.hpp"
using namespace RTC;
namespace fuzzers
{
void fuzzStun(const uint8_t* data, size_t len)
{
if (!StunMessage::IsStun(data, len))
return;
StunMessage* msg = StunMessage::Parse(data, len);
if (!msg)
return;
msg->Dump();
msg->GetClass();
msg->GetMethod();
msg->GetData();
msg->GetSize();
msg->SetUsername("foo", 3);
msg->SetPriority(123);
msg->SetIceControlling(123);
msg->SetIceControlled(123);
msg->SetUseCandidate();
// TODO: msg->SetXorMappedAddress();
msg->SetErrorCode(666);
// TODO: msg->SetMessageIntegrity();
msg->SetFingerprint();
msg->GetUsername();
msg->GetPriority();
msg->GetIceControlling();
msg->GetIceControlled();
msg->HasUseCandidate();
msg->GetErrorCode();
msg->HasMessageIntegrity();
msg->HasFingerprint();
msg->CheckAuthentication("foo", "bar");
// TODO: msg->CreateSuccessResponse(); // This cannot be easily tested.
// TODO: msg->CreateErrorResponse(); // This cannot be easily tested.
msg->Authenticate("lalala");
// TODO: Cannot test Serialize() because we don't know the exact required
// buffer size (setters above may change the total size).
// TODO: msg->Serialize();
delete msg;
}
}
......@@ -6,7 +6,9 @@
#include "Logger.hpp"
#include "Settings.hpp"
#include "Utils.hpp"
#include "fuzzers.hpp"
#include "RTC/FuzzerStunMessage.hpp"
#include "RTC/FuzzerRtpPacket.hpp"
#include "RTC/RTCP/FuzzerPacket.hpp"
#include <stdint.h>
#include <stddef.h>
#include <cstdlib> // std::getenv()
......@@ -63,13 +65,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len)
static int unused = init();
if (fuzzStun)
fuzzers::fuzzStun(data, len);
Fuzzer::RTC::StunMessage::Fuzz(data, len);
if (fuzzRtp)
fuzzers::fuzzRtp(data, len);
Fuzzer::RTC::RtpPacket::Fuzz(data, len);
if (fuzzRtcp)
fuzzers::fuzzRtcp(data, len);
Fuzzer::RTC::RTCP::Packet::Fuzz(data, len);
return 0;
}
......@@ -265,34 +265,34 @@
'sources':
[
# C++ source files
'test/tests.cpp',
'test/RTC/TestRtpStreamSend.cpp',
'test/RTC/TestNackGenerator.cpp',
'test/RTC/TestRtpPacket.cpp',
'test/RTC/TestRtpDataCounter.cpp',
'test/RTC/TestRtpMonitor.cpp',
'test/RTC/TestRtpStreamRecv.cpp',
'test/RTC/TestSeqManager.cpp',
'test/RTC/Codecs/TestVP8.cpp',
'test/RTC/RTCP/TestFeedbackPsAfb.cpp',
'test/RTC/RTCP/TestFeedbackPsFir.cpp',
'test/RTC/RTCP/TestFeedbackPsLei.cpp',
'test/RTC/RTCP/TestFeedbackPsPli.cpp',
'test/RTC/RTCP/TestFeedbackPsRemb.cpp',
'test/RTC/RTCP/TestFeedbackPsRpsi.cpp',
'test/RTC/RTCP/TestFeedbackPsSli.cpp',
'test/RTC/RTCP/TestFeedbackPsTst.cpp',
'test/RTC/RTCP/TestFeedbackPsVbcm.cpp',
'test/RTC/RTCP/TestFeedbackRtpEcn.cpp',
'test/RTC/RTCP/TestFeedbackRtpNack.cpp',
'test/RTC/RTCP/TestFeedbackRtpSrReq.cpp',
'test/RTC/RTCP/TestFeedbackRtpTllei.cpp',
'test/RTC/RTCP/TestFeedbackRtpTmmb.cpp',
'test/RTC/RTCP/TestBye.cpp',
'test/RTC/RTCP/TestReceiverReport.cpp',
'test/RTC/RTCP/TestSdes.cpp',
'test/RTC/RTCP/TestSenderReport.cpp',
'test/RTC/RTCP/TestPacket.cpp',
'test/src/tests.cpp',
'test/src/RTC/TestRtpStreamSend.cpp',
'test/src/RTC/TestNackGenerator.cpp',
'test/src/RTC/TestRtpPacket.cpp',
'test/src/RTC/TestRtpDataCounter.cpp',
'test/src/RTC/TestRtpMonitor.cpp',
'test/src/RTC/TestRtpStreamRecv.cpp',
'test/src/RTC/TestSeqManager.cpp',
'test/src/RTC/Codecs/TestVP8.cpp',
'test/src/RTC/RTCP/TestFeedbackPsAfb.cpp',
'test/src/RTC/RTCP/TestFeedbackPsFir.cpp',
'test/src/RTC/RTCP/TestFeedbackPsLei.cpp',
'test/src/RTC/RTCP/TestFeedbackPsPli.cpp',
'test/src/RTC/RTCP/TestFeedbackPsRemb.cpp',
'test/src/RTC/RTCP/TestFeedbackPsRpsi.cpp',
'test/src/RTC/RTCP/TestFeedbackPsSli.cpp',
'test/src/RTC/RTCP/TestFeedbackPsTst.cpp',
'test/src/RTC/RTCP/TestFeedbackPsVbcm.cpp',
'test/src/RTC/RTCP/TestFeedbackRtpEcn.cpp',
'test/src/RTC/RTCP/TestFeedbackRtpNack.cpp',
'test/src/RTC/RTCP/TestFeedbackRtpSrReq.cpp',
'test/src/RTC/RTCP/TestFeedbackRtpTllei.cpp',
'test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp',
'test/src/RTC/RTCP/TestBye.cpp',
'test/src/RTC/RTCP/TestReceiverReport.cpp',
'test/src/RTC/RTCP/TestSdes.cpp',
'test/src/RTC/RTCP/TestSenderReport.cpp',
'test/src/RTC/RTCP/TestPacket.cpp',
# C++ include files
'test/include/catch.hpp',
'test/include/helpers.hpp'
......@@ -303,7 +303,8 @@
],
'xcode_settings':
{
'OTHER_CPLUSPLUSFLAGS': [
'OTHER_CPLUSPLUSFLAGS':
[
'--coverage'
],
'OTHER_LDFLAGS': [
......@@ -317,12 +318,14 @@
'sources':
[
# C++ source files
'fuzzer/fuzzer.cpp',
'fuzzer/src/fuzzStun.cpp',
'fuzzer/src/fuzzRtp.cpp',
'fuzzer/src/fuzzRtcp.cpp',
'fuzzer/src/fuzzer.cpp',
'fuzzer/src/RTC/FuzzerStunMessage.cpp',
'fuzzer/src/RTC/FuzzerRtpPacket.cpp',
'fuzzer/src/RTC/RTCP/FuzzerPacket.cpp',
# C++ include files
'fuzzer/include/fuzzers.hpp'
'fuzzer/include/RTC/FuzzerStunMessage.hpp',
'fuzzer/include/RTC/FuzzerRtpPacket.hpp',
'fuzzer/include/RTC/RTCP/FuzzerPacket.hpp'
],
'include_dirs':
[
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论