From 29a49dbb09b688da15953b06b991124d40f4d637 Mon Sep 17 00:00:00 2001 From: Patrick McManus Date: Mon, 8 Apr 2013 12:02:41 -0400 Subject: [PATCH] bug 857291 - fix 807678 regression of DNS::GetCanonicalName r=josh --- netwerk/dns/DNS.cpp | 11 ++++++++++- netwerk/dns/DNS.h | 4 +++- netwerk/dns/nsDNSService2.cpp | 4 +++- netwerk/dns/nsHostResolver.cpp | 5 ++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/netwerk/dns/DNS.cpp b/netwerk/dns/DNS.cpp index 529f03a5afc0..973ce247c40a 100644 --- a/netwerk/dns/DNS.cpp +++ b/netwerk/dns/DNS.cpp @@ -176,11 +176,19 @@ NetAddrElement::~NetAddrElement() } AddrInfo::AddrInfo(const char *host, const PRAddrInfo *prAddrInfo, - bool disableIPv4) + bool disableIPv4, const char *cname) { size_t hostlen = strlen(host); mHostName = static_cast(moz_xmalloc(hostlen + 1)); memcpy(mHostName, host, hostlen + 1); + if (cname) { + size_t cnameLen = strlen(cname); + mCanonicalName = static_cast(moz_xmalloc(cnameLen + 1)); + memcpy(mCanonicalName, cname, cnameLen + 1); + } + else { + mCanonicalName = nullptr; + } PRNetAddr tmpAddr; void *iter = nullptr; @@ -200,6 +208,7 @@ AddrInfo::~AddrInfo() delete addrElement; } moz_free(mHostName); + moz_free(mCanonicalName); } } // namespace dns diff --git a/netwerk/dns/DNS.h b/netwerk/dns/DNS.h index ddedb913d0c0..53841a0ffd89 100644 --- a/netwerk/dns/DNS.h +++ b/netwerk/dns/DNS.h @@ -121,10 +121,12 @@ public: class AddrInfo { public: - AddrInfo(const char *host, const PRAddrInfo *prAddrInfo, bool disableIPv4); + AddrInfo(const char *host, const PRAddrInfo *prAddrInfo, bool disableIPv4, + const char *cname); ~AddrInfo(); char *mHostName; + char *mCanonicalName; LinkedList mAddresses; }; diff --git a/netwerk/dns/nsDNSService2.cpp b/netwerk/dns/nsDNSService2.cpp index 93afd604de75..4b9ec14a128a 100644 --- a/netwerk/dns/nsDNSService2.cpp +++ b/netwerk/dns/nsDNSService2.cpp @@ -83,7 +83,9 @@ nsDNSRecord::GetCanonicalName(nsACString &result) { MutexAutoLock lock(mHostRecord->addr_info_lock); if (mHostRecord->addr_info) - cname = mHostRecord->addr_info->mHostName; + cname = mHostRecord->addr_info->mCanonicalName ? + mHostRecord->addr_info->mCanonicalName : + mHostRecord->addr_info->mHostName; else cname = mHostRecord->host; result.Assign(cname); diff --git a/netwerk/dns/nsHostResolver.cpp b/netwerk/dns/nsHostResolver.cpp index 9da34062b686..ef652f9c017b 100644 --- a/netwerk/dns/nsHostResolver.cpp +++ b/netwerk/dns/nsHostResolver.cpp @@ -997,7 +997,10 @@ nsHostResolver::ThreadFunc(void *arg) nsresult status; AddrInfo *ai = nullptr; if (prai) { - ai = new AddrInfo(rec->host, prai, disableIPv4); + const char *cname = nullptr; + if (rec->flags & RES_CANON_NAME) + cname = PR_GetCanonNameFromAddrInfo(prai); + ai = new AddrInfo(rec->host, prai, disableIPv4, cname); PR_FreeAddrInfo(prai); if (ai->mAddresses.isEmpty()) { delete ai;