aboutsummaryrefslogtreecommitdiff
path: root/src/agent
diff options
context:
space:
mode:
authorSimon Lin <simonlin@google.com>2021-06-08 12:35:04 +0800
committerGitHub <noreply@github.com>2021-06-07 21:35:04 -0700
commitfaed2f0929121c1525b70af9c66aff7b2c9c80bc (patch)
treea3ec3409a36be6ea17c93a3dda8fe192a5a4bfa6 /src/agent
parente4c8f08e56bbfaa1769f090711ff6c3c83b158fe (diff)
downloadot-br-posix-faed2f0929121c1525b70af9c66aff7b2c9c80bc.tar.gz
[dns] fix potential discovery proxy crash (#867)
This commit fixes potential Discovery Proxy crash when the mDNS implementation replied with an empty host name.
Diffstat (limited to 'src/agent')
-rw-r--r--src/agent/discovery_proxy.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/agent/discovery_proxy.cpp b/src/agent/discovery_proxy.cpp
index 407fe3a8..02f798a0 100644
--- a/src/agent/discovery_proxy.cpp
+++ b/src/agent/discovery_proxy.cpp
@@ -222,12 +222,18 @@ void DiscoveryProxy::OnHostDiscovered(const std::string &
const Mdns::Publisher::DiscoveredHostInfo &aHostInfo)
{
otDnssdHostInfo hostInfo;
- const otDnssdQuery *query = nullptr;
+ const otDnssdQuery *query = nullptr;
+ std::string resolvedHostName = aHostInfo.mHostName;
otbrLogInfo("host discovered: %s hostname %s addresses %zu", aHostName.c_str(), aHostInfo.mHostName.c_str(),
aHostInfo.mAddresses.size());
- CheckHostnameSanity(aHostInfo.mHostName);
+ if (resolvedHostName.empty())
+ {
+ resolvedHostName = aHostName + ".local.";
+ }
+
+ CheckHostnameSanity(resolvedHostName);
hostInfo.mAddressNum = aHostInfo.mAddresses.size();
if (!aHostInfo.mAddresses.empty())
@@ -257,7 +263,7 @@ void DiscoveryProxy::OnHostDiscovered(const std::string &
if (hostName == aHostName)
{
- std::string hostFullName = TranslateDomain(aHostInfo.mHostName, domain);
+ std::string hostFullName = TranslateDomain(resolvedHostName, domain);
otDnssdQueryHandleDiscoveredHost(mNcp.GetInstance(), hostFullName.c_str(), &hostInfo);
}