Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mdns] Added two nullptr checks to prevent falling into hard fault #24233

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[mdns] Added two nullptr checks to prevent falling into hard fault
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 committed Jan 3, 2023
commit 574e46d1f8e4e003129de8f82638a9f70650cde4
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