Skip to content

Commit

Permalink
Add checks for empty domain
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple committed Mar 19, 2024
1 parent 9ea1ed0 commit 502082e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/platform/Darwin/DnssdContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,14 @@ void ResolveContext::OnNewInterface(uint32_t interfaceId, const char * fullname,
// resolving.
interface.fullyQualifiedDomainName = hostnameWithDomain;

std::pair<uint32_t, std::string> interfaceKey = std::make_pair(interfaceId, GetDomainNameFromHostName(hostnameWithDomain));
std::string domainFromHostname = GetDomainFromHostName(hostnameWithDomain);
if (domainFromHostname.empty())
{
ChipLogError(Discovery, "Mdns: Domain from hostname is empty");
return;
}

std::pair<uint32_t, std::string> interfaceKey = std::make_pair(interfaceId, domainFromHostname);

interfaces.insert(std::make_pair(interfaceKey, std::move(interface)));
}
Expand Down
9 changes: 7 additions & 2 deletions src/platform/Darwin/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace chip {
namespace Dnssd {


std::string GetDomainNameFromHostName(const char * hostname)
std::string GetDomainFromHostName(const char * hostname)
{
if (HostNameHasDomain(hostname, kLocalDot))
{
Expand Down Expand Up @@ -293,7 +293,12 @@ static void OnGetAddrInfo(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t i
ReturnOnFailure(MdnsContexts::GetInstance().Has(sdCtx));
LogOnFailure(__func__, err);

sdCtx->domainName = GetDomainNameFromHostName(hostname);
sdCtx->domainName = GetDomainFromHostName(hostname);
if (sdCtx->domainName.empty())
{
ChipLogError(Discovery, "Mdns: Domain name is not set");
return;
}
if (kDNSServiceErr_NoError == err)
{
std::pair<uint32_t, std::string> key = std::make_pair(interfaceId, sdCtx->domainName);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Darwin/DnssdImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ constexpr char kOpenThreadDot[] = "openthread.thread.home.arpa";
namespace chip {
namespace Dnssd {

std::string GetDomainNameFromHostName(const char * hostname);
std::string GetDomainFromHostName(const char * hostname);

enum class ContextType
{
Expand Down

0 comments on commit 502082e

Please sign in to comment.