Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libfuzzer] Fuzzing different Transport Types for all-clusters-app #35629

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions examples/all-clusters-app/linux/fuzzing-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize)
// For now, just dump the data as a UDP payload into the session manager.
// But maybe we should try to separately extract a PeerAddress and data from
// the incoming data?
Transport::PeerAddress peerAddr;

// dumping payload with random transport types
Transport::Type fuzzedTransportType = static_cast<Transport::Type>(*aData % 5);
Alami-Amine marked this conversation as resolved.
Show resolved Hide resolved
Alami-Amine marked this conversation as resolved.
Show resolved Hide resolved
Transport::PeerAddress peerAddr(fuzzedTransportType);

System::PacketBufferHandle buf =
System::PacketBufferHandle::NewWithData(aData, aSize, /* aAdditionalSize = */ 0, /* aReservedSize = */ 0);
if (buf.IsNull())
Expand All @@ -84,8 +88,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize)

// Ignoring the return value from OnMessageReceived, because we might be
// passing it all sorts of garbage that will cause it to fail.
Server::GetInstance().GetSecureSessionManager().OnMessageReceived(peerAddr, std::move(buf));

// for TCP we need to have MessageTransportContext
if (fuzzedTransportType == Transport::Type::kTcp)
{
Transport::MessageTransportContext msgContext;
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
Server::GetInstance().GetSecureSessionManager().OnMessageReceived(peerAddr, std::move(buf), &msgContext);
}
else
{
Server::GetInstance().GetSecureSessionManager().OnMessageReceived(peerAddr, std::move(buf));
}
// Now process pending events until our sentinel is reached.
PlatformMgr().ScheduleWork([](intptr_t) { PlatformMgr().StopEventLoopTask(); });
PlatformMgr().RunEventLoop();
Expand Down
Loading