Skip to content

Commit

Permalink
Add null check to MinimalMdns Server when calling CloneData
Browse files Browse the repository at this point in the history
  • Loading branch information
s-mcclain committed Sep 7, 2022
1 parent 7b6c891 commit bfe230f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/inet/UDPEndPointImplSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ 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_NO_MEMORY);
VerifyOrReturnError(!msg.IsNull(), CHIP_ERROR_INVALID_ARGUMENT);

// Make sure we have the appropriate type of socket based on the
// destination address.
Expand Down
11 changes: 8 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,19 @@ 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)
PacketBufferHandle tempBuf = data.CloneData();
if (tempBuf.IsNull()) {
// 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, data.CloneData(), udp->GetBoundInterface());
err = udp->SendTo(mIpv6BroadcastAddress, port, 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, tempBuf, udp->GetBoundInterface());
}
#endif
else
Expand Down

0 comments on commit bfe230f

Please sign in to comment.