diff --git a/src/inet/UDPEndPointImplSockets.cpp b/src/inet/UDPEndPointImplSockets.cpp index 131e20d9709b23..cd12fe42fb64d3 100644 --- a/src/inet/UDPEndPointImplSockets.cpp +++ b/src/inet/UDPEndPointImplSockets.cpp @@ -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())); diff --git a/src/lib/dnssd/minimal_mdns/Server.cpp b/src/lib/dnssd/minimal_mdns/Server.cpp index 1dc54bfa81e6d3..9db53bee0c4c6c 100644 --- a/src/lib/dnssd/minimal_mdns/Server.cpp +++ b/src/lib/dnssd/minimal_mdns/Server.cpp @@ -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