Skip to content

Commit

Permalink
NULL check in UDPEndPoint Sockets SendMsgImpl (#22432)
Browse files Browse the repository at this point in the history
* Add IsNull check to UDP Sockets SendMsgImpl prior to ptr dereference.

* Update UDPEndPointImplSockets.cpp

Moved msg.IsNull check to beginning of SendMsgImpl

* Add null check to MinimalMdns Server when calling CloneData

* Restyle

* Add namespace for PacketBufferHandle

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 14, 2023
1 parent 529b747 commit 3564397
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/inet/UDPEndPointImplSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ CHIP_ERROR UDPEndPointImplSockets::ListenImpl()

CHIP_ERROR UDPEndPointImplSockets::SendMsgImpl(const IPPacketInfo * aPktInfo, System::PacketBufferHandle && msg)
{
// Ensure packet buffer is not null
VerifyOrReturnError(!msg.IsNull(), CHIP_ERROR_INVALID_ARGUMENT);

// Make sure we have the appropriate type of socket based on the
// destination address.
ReturnErrorOnFailure(GetSocket(aPktInfo->DestAddress.Type()));
Expand Down
12 changes: 9 additions & 3 deletions src/lib/dnssd/minimal_mdns/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,20 @@ CHIP_ERROR ServerBase::BroadcastImpl(chip::System::PacketBufferHandle && data, u
/// for sending via `CloneData`
///
/// TODO: this wastes one copy of the data and that could be optimized away
if (info->mAddressType == chip::Inet::IPAddressType::kIPv6)
chip::System::PacketBufferHandle tempBuf = data.CloneData();
if (tempBuf.IsNull())
{
err = udp->SendTo(mIpv6BroadcastAddress, port, data.CloneData(), udp->GetBoundInterface());
// Not enough memory available to clone pbuf
err = CHIP_ERROR_NO_MEMORY;
}
else if (info->mAddressType == chip::Inet::IPAddressType::kIPv6)
{
err = udp->SendTo(mIpv6BroadcastAddress, port, std::move(tempBuf), udp->GetBoundInterface());
}
#if INET_CONFIG_ENABLE_IPV4
else if (info->mAddressType == chip::Inet::IPAddressType::kIPv4)
{
err = udp->SendTo(mIpv4BroadcastAddress, port, data.CloneData(), udp->GetBoundInterface());
err = udp->SendTo(mIpv4BroadcastAddress, port, std::move(tempBuf), udp->GetBoundInterface());
}
#endif
else
Expand Down

0 comments on commit 3564397

Please sign in to comment.