Skip to content

Commit

Permalink
Gracefully handle non-DNS-SD results from DNSServiceGetAddrInfo. (#24715
Browse files Browse the repository at this point in the history
)

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 pull[bot] committed Jul 17, 2023
1 parent 4879eac commit 6831541
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 6831541

Please sign in to comment.