From 6831541eef3b64e13ac97ca2fcdd7cfc985b020d Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 30 Jan 2023 12:19:59 -0500 Subject: [PATCH] Gracefully handle non-DNS-SD results from DNSServiceGetAddrInfo. (#24715) If we don't do this, then we'll add an entry to "interfaces" that does not have most of the necessary data defined, and if we pick that interface to then report to whatever started the resolve, things will fail out. --- src/platform/Darwin/DnssdContexts.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/platform/Darwin/DnssdContexts.cpp b/src/platform/Darwin/DnssdContexts.cpp index b433dc47a418c7..e939c253fe6cd2 100644 --- a/src/platform/Darwin/DnssdContexts.cpp +++ b/src/platform/Darwin/DnssdContexts.cpp @@ -381,6 +381,17 @@ void ResolveContext::DispatchSuccess() CHIP_ERROR ResolveContext::OnNewAddress(uint32_t interfaceId, const struct sockaddr * address) { + // If we don't have any information about this interfaceId, just ignore the + // address, since it won't be usable anyway without things like the port. + // This can happen if "local" is set up as a search domain in the DNS setup + // on the system, because the hostnames we are looking up all end in + // ".local". In other words, we can get regular DNS results in here, not + // just DNS-SD ones. + if (interfaces.find(interfaceId) == interfaces.end()) + { + return CHIP_NO_ERROR; + } + chip::Inet::IPAddress ip; ReturnErrorOnFailure(chip::Inet::IPAddress::GetIPAddressFromSockAddr(*address, ip)); interfaces[interfaceId].addresses.push_back(ip);