Skip to content

Commit

Permalink
[mdns] Added two nullptr checks to prevent falling into hard fault (#…
Browse files Browse the repository at this point in the history
…24233)

In mDNS code there isn't a check that would verify if memory
was allocated successfully using new. In case it didn't the
application will fall into hard fault due to usage of
non-allocated memory.

Added two checks verifying that memory was allocated
successfully before using.
  • Loading branch information
kkasperczyk-no authored Jan 4, 2023
1 parent 23e5fb2 commit ff845ba
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,13 +878,15 @@ void AdvertiserMinMdns::AdvertiseRecords(BroadcastAdvertiseType type)
}

UniquePtr<ListenIterator> allInterfaces = GetAddressPolicy()->GetListenEndpoints();
VerifyOrDieWithMsg(allInterfaces != nullptr, Discovery, "Failed to allocate memory for endpoints.");

chip::Inet::InterfaceId interfaceId;
chip::Inet::IPAddressType addressType;

while (allInterfaces->Next(&interfaceId, &addressType))
{
UniquePtr<IpAddressIterator> allIps = GetAddressPolicy()->GetIpAddressesForEndpoint(interfaceId, addressType);
VerifyOrDieWithMsg(allIps != nullptr, Discovery, "Failed to allocate memory for ip addresses.");

Inet::IPAddress ipAddress;
while (allIps->Next(ipAddress))
Expand Down

0 comments on commit ff845ba

Please sign in to comment.