提交 12670f7a authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

fuzzer: split code into different fuzzers for STUN, RTP and RTCP

上级 c75cd57b
...@@ -5,16 +5,13 @@ ...@@ -5,16 +5,13 @@
#include "LogLevel.hpp" #include "LogLevel.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "Settings.hpp" #include "Settings.hpp"
#include "RTC/StunMessage.hpp" #include "Utils.hpp"
#include "RTC/RtpPacket.hpp" #include "fuzzers.hpp"
#include "RTC/RTCP/Packet.hpp"
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <cstdlib> // std::getenv() #include <cstdlib> // std::getenv()
#include <iostream> #include <iostream>
using namespace RTC;
bool fuzzStun = false; bool fuzzStun = false;
bool fuzzRtcp = false; bool fuzzRtcp = false;
bool fuzzRtp = false; bool fuzzRtp = false;
...@@ -60,44 +57,19 @@ int init() ...@@ -60,44 +57,19 @@ int init()
return 0; return 0;
} }
void fuzz(const uint8_t* data, size_t len)
{
if (fuzzStun && StunMessage::IsStun(data, len))
{
StunMessage* msg = StunMessage::Parse(data, len);
if (msg)
delete msg;
}
if (fuzzRtcp && RTCP::Packet::IsRtcp(data, len))
{
RTCP::Packet* packet = RTCP::Packet::Parse(data, len);
while (packet != nullptr)
{
auto* previousPacket = packet;
packet = packet->GetNext();
delete previousPacket;
}
}
if (fuzzRtp && RtpPacket::IsRtp(data, len))
{
RtpPacket* packet = RtpPacket::Parse(data, len);
if (packet)
delete packet;
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len)
{ {
// Trick to initialize our stuff just once. // Trick to initialize our stuff just once.
static int unused = init(); static int unused = init();
fuzz(data, len); if (fuzzStun)
fuzzers::fuzzStun(data, len);
if (fuzzRtp)
fuzzers::fuzzRtp(data, len);
if (fuzzRtcp)
fuzzers::fuzzRtcp(data, len);
return 0; return 0;
} }
#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 "fuzzers.hpp"
#include "RTC/RTCP/Packet.hpp"
using namespace RTC;
namespace fuzzers
{
void fuzzRtp(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"
using namespace RTC;
namespace fuzzers
{
void fuzzRtcp(const uint8_t* data, size_t len)
{
if (!RtpPacket::IsRtp(data, len))
return;
RtpPacket* packet = RtpPacket::Parse(data, len);
if (!packet)
return;
// TODO: Add more checks here.
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;
// TODO: Add more checks here.
delete msg;
}
}
...@@ -294,8 +294,8 @@ ...@@ -294,8 +294,8 @@
'test/RTC/RTCP/TestSenderReport.cpp', 'test/RTC/RTCP/TestSenderReport.cpp',
'test/RTC/RTCP/TestPacket.cpp', 'test/RTC/RTCP/TestPacket.cpp',
# C++ include files # C++ include files
'include/catch.hpp', 'test/include/catch.hpp',
'include/helpers.hpp' 'test/include/helpers.hpp'
], ],
'include_dirs': 'include_dirs':
[ [
...@@ -317,7 +317,16 @@ ...@@ -317,7 +317,16 @@
'sources': 'sources':
[ [
# C++ source files # C++ source files
'fuzzer/fuzzer.cpp' 'fuzzer/fuzzer.cpp',
'fuzzer/src/fuzzStun.cpp',
'fuzzer/src/fuzzRtp.cpp',
'fuzzer/src/fuzzRtcp.cpp',
# C++ include files
'fuzzer/include/fuzzers.hpp'
],
'include_dirs':
[
'fuzzer/include'
], ],
'conditions': 'conditions':
[ [
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "Logger.hpp" #include "Logger.hpp"
#include "Settings.hpp" #include "Settings.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "include/catch.hpp" #include "catch.hpp"
#include <string> #include <string>
static void init(); static void init();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论