bug 857291 - fix 807678 regression of DNS::GetCanonicalName r=josh

This commit is contained in:
Patrick McManus 2013-04-08 12:02:41 -04:00
parent e029597932
commit afd013ce0b
4 changed files with 20 additions and 4 deletions

View File

@ -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<char*>(moz_xmalloc(hostlen + 1));
memcpy(mHostName, host, hostlen + 1);
if (cname) {
size_t cnameLen = strlen(cname);
mCanonicalName = static_cast<char*>(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

View File

@ -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<NetAddrElement> mAddresses;
};

View File

@ -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);

View File

@ -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;