Skip to content

Commit

Permalink
Gracefully handle non-DNS-SD results from DNSServiceGetAddrInfo. (pro…
Browse files Browse the repository at this point in the history
…ject-chip#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.
  • Loading branch information
bzbarsky-apple authored and David Lechner committed Mar 22, 2023
1 parent 262c794 commit 9b40af1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/platform/Darwin/DnssdContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9b40af1

Please sign in to comment.