From 9b7c7ec8533d69e44f502802df8c87848e376ab1 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com> Date: Wed, 4 Jan 2023 10:34:31 +0100 Subject: [PATCH] [mdns] Added two nullptr checks to prevent falling into hard fault (#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. --- src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp index 6153ee8245f37a..d38b8f5ff1e37d 100644 --- a/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp @@ -878,6 +878,7 @@ void AdvertiserMinMdns::AdvertiseRecords(BroadcastAdvertiseType type) } UniquePtr allInterfaces = GetAddressPolicy()->GetListenEndpoints(); + VerifyOrDieWithMsg(allInterfaces != nullptr, Discovery, "Failed to allocate memory for endpoints."); chip::Inet::InterfaceId interfaceId; chip::Inet::IPAddressType addressType; @@ -885,6 +886,7 @@ void AdvertiserMinMdns::AdvertiseRecords(BroadcastAdvertiseType type) while (allInterfaces->Next(&interfaceId, &addressType)) { UniquePtr allIps = GetAddressPolicy()->GetIpAddressesForEndpoint(interfaceId, addressType); + VerifyOrDieWithMsg(allIps != nullptr, Discovery, "Failed to allocate memory for ip addresses."); Inet::IPAddress ipAddress; while (allIps->Next(ipAddress))