Skip to content

Commit 1db065e

Browse files
committed
Fuzzing different Transport Types for all-clusters-app
1 parent 514e810 commit 1db065e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

examples/all-clusters-app/linux/fuzzing-main.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize)
7373
// For now, just dump the data as a UDP payload into the session manager.
7474
// But maybe we should try to separately extract a PeerAddress and data from
7575
// the incoming data?
76-
Transport::PeerAddress peerAddr;
76+
77+
// dumping payload with random transport types
78+
Transport::Type randomTransportType = static_cast<Transport::Type>(*aData % 5);
79+
Transport::PeerAddress peerAddr(randomTransportType);
80+
7781
System::PacketBufferHandle buf =
7882
System::PacketBufferHandle::NewWithData(aData, aSize, /* aAdditionalSize = */ 0, /* aReservedSize = */ 0);
7983
if (buf.IsNull())
@@ -84,8 +88,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize)
8488

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

92+
// for TCP we need to have MessageTransportContext
93+
if (randomTransportType == Transport::Type::kTcp)
94+
{
95+
Transport::MessageTransportContext msgContext;
96+
Server::GetInstance().GetSecureSessionManager().OnMessageReceived(peerAddr, std::move(buf), &msgContext);
97+
}
98+
else
99+
{
100+
Server::GetInstance().GetSecureSessionManager().OnMessageReceived(peerAddr, std::move(buf));
101+
}
89102
// Now process pending events until our sentinel is reached.
90103
PlatformMgr().ScheduleWork([](intptr_t) { PlatformMgr().StopEventLoopTask(); });
91104
PlatformMgr().RunEventLoop();

0 commit comments

Comments
 (0)