Bug 1417827 - Pass DNS arguments as nsACString& instead of char* r=bagder
authorValentin Gosu <valentin.gosu@gmail.com>
Fri, 15 Jun 2018 01:15:13 +0200
changeset 422599 cb84b0e19643f215290c367bee8ad63e4c6aef7b
parent 422598 535a93ad81a1c1d7d81205373b92c49191637f4b
child 422600 b40de0d36037f68e747fb362d084a6858ac9b02f
push id65205
push uservalentin.gosu@gmail.com
push dateThu, 14 Jun 2018 23:59:38 +0000
treeherderautoland@cb84b0e19643 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1417827
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1417827 - Pass DNS arguments as nsACString& instead of char* r=bagder MozReview-Commit-ID: 7Zk0wM2wsJF
netwerk/dns/GetAddrInfo.cpp
netwerk/dns/GetAddrInfo.h
netwerk/dns/TRR.cpp
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsHostResolver.cpp
netwerk/dns/nsHostResolver.h
--- a/netwerk/dns/GetAddrInfo.cpp
+++ b/netwerk/dns/GetAddrInfo.cpp
@@ -191,19 +191,19 @@ static MOZ_ALWAYS_INLINE nsresult
     }
   }
 
   dnsapi->mDnsFreeFunc(dnsData, DNS_FREE_TYPE::DnsFreeRecordList);
   return NS_OK;
 }
 
 static MOZ_ALWAYS_INLINE nsresult
-_GetTTLData_Windows(const char* aHost, uint32_t* aResult, uint16_t aAddressFamily)
+_GetTTLData_Windows(const nsACString& aHost, uint32_t* aResult, uint16_t aAddressFamily)
 {
-  MOZ_ASSERT(aHost);
+  MOZ_ASSERT(!aHost.IsEmpty());
   MOZ_ASSERT(aResult);
   if (aAddressFamily != PR_AF_UNSPEC &&
       aAddressFamily != PR_AF_INET &&
       aAddressFamily != PR_AF_INET6) {
     return NS_ERROR_UNEXPECTED;
   }
 
   RefPtr<DnsapiInfo> dnsapi = nullptr;
@@ -217,20 +217,20 @@ static MOZ_ALWAYS_INLINE nsresult
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // In order to avoid using ANY records which are not always implemented as a
   // "Gimme what you have" request in hostname resolvers, we should send A
   // and/or AAAA requests, based on the address family requested.
   unsigned int ttl = (unsigned int)-1;
   if (aAddressFamily == PR_AF_UNSPEC || aAddressFamily == PR_AF_INET) {
-    _GetMinTTLForRequestType_Windows(dnsapi, aHost, DNS_TYPE_A, &ttl);
+    _GetMinTTLForRequestType_Windows(dnsapi, aHost.BeginReading(), DNS_TYPE_A, &ttl);
   }
   if (aAddressFamily == PR_AF_UNSPEC || aAddressFamily == PR_AF_INET6) {
-    _GetMinTTLForRequestType_Windows(dnsapi, aHost, DNS_TYPE_AAAA, &ttl);
+    _GetMinTTLForRequestType_Windows(dnsapi, aHost.BeginReading(), DNS_TYPE_AAAA, &ttl);
   }
 
   {
     // dnsapi's destructor is not thread-safe, so we release explicitly here
     OffTheBooksMutexAutoLock lock(*gDnsapiInfoLock);
     dnsapi = nullptr;
   }
 
@@ -244,20 +244,20 @@ static MOZ_ALWAYS_INLINE nsresult
 }
 #endif
 
 ////////////////////////////////////
 // PORTABLE RUNTIME IMPLEMENTATION//
 ////////////////////////////////////
 
 static MOZ_ALWAYS_INLINE nsresult
-_GetAddrInfo_Portable(const char* aCanonHost, uint16_t aAddressFamily,
+_GetAddrInfo_Portable(const nsACString& aCanonHost, uint16_t aAddressFamily,
                       uint16_t aFlags, AddrInfo** aAddrInfo)
 {
-  MOZ_ASSERT(aCanonHost);
+  MOZ_ASSERT(!aCanonHost.IsEmpty());
   MOZ_ASSERT(aAddrInfo);
 
   // We accept the same aFlags that nsHostResolver::ResolveHost accepts, but we
   // need to translate the aFlags into a form that PR_GetAddrInfoByName
   // accepts.
   int prFlags = PR_AI_ADDRCONFIG;
   if (!(aFlags & nsHostResolver::RES_CANON_NAME)) {
     prFlags |= PR_AI_NOCANONNAME;
@@ -265,30 +265,30 @@ static MOZ_ALWAYS_INLINE nsresult
 
   // We need to remove IPv4 records manually because PR_GetAddrInfoByName
   // doesn't support PR_AF_INET6.
   bool disableIPv4 = aAddressFamily == PR_AF_INET6;
   if (disableIPv4) {
     aAddressFamily = PR_AF_UNSPEC;
   }
 
-  PRAddrInfo* prai = PR_GetAddrInfoByName(aCanonHost, aAddressFamily, prFlags);
+  PRAddrInfo* prai = PR_GetAddrInfoByName(aCanonHost.BeginReading(), aAddressFamily, prFlags);
 
   if (!prai) {
     return NS_ERROR_UNKNOWN_HOST;
   }
 
-  const char* canonName = nullptr;
+  nsAutoCString canonName;
   if (aFlags & nsHostResolver::RES_CANON_NAME) {
-    canonName = PR_GetCanonNameFromAddrInfo(prai);
+    canonName.Assign(PR_GetCanonNameFromAddrInfo(prai));
   }
 
   bool filterNameCollision = !(aFlags & nsHostResolver::RES_ALLOW_NAME_COLLISION);
-  nsAutoPtr<AddrInfo> ai(new AddrInfo(nsCString(aCanonHost), prai, disableIPv4,
-                                      filterNameCollision, nsCString(canonName)));
+  nsAutoPtr<AddrInfo> ai(new AddrInfo(aCanonHost, prai, disableIPv4,
+                                      filterNameCollision, canonName));
   PR_FreeAddrInfo(prai);
   if (ai->mAddresses.isEmpty()) {
     return NS_ERROR_UNKNOWN_HOST;
   }
 
   *aAddrInfo = ai.forget();
 
   return NS_OK;
@@ -315,59 +315,60 @@ GetAddrInfoShutdown() {
 #ifdef DNSQUERY_AVAILABLE
   return _GetAddrInfoShutdown_Windows();
 #else
   return NS_OK;
 #endif
 }
 
 nsresult
-GetAddrInfo(const char* aHost, uint16_t aAddressFamily, uint16_t aFlags,
+GetAddrInfo(const nsACString& aHost, uint16_t aAddressFamily, uint16_t aFlags,
             AddrInfo** aAddrInfo, bool aGetTtl)
 {
-  if (NS_WARN_IF(!aHost) || NS_WARN_IF(!aAddrInfo)) {
+  if (NS_WARN_IF(aHost.IsEmpty()) || NS_WARN_IF(!aAddrInfo)) {
     return NS_ERROR_NULL_POINTER;
   }
 
 #ifdef DNSQUERY_AVAILABLE
   // The GetTTLData needs the canonical name to function properly
   if (aGetTtl) {
     aFlags |= nsHostResolver::RES_CANON_NAME;
   }
 #endif
 
+  nsAutoCString host(aHost);
   if (gNativeIsLocalhost) {
     // pretend we use the given host but use IPv4 localhost instead!
-    aHost = "localhost";
+    host = NS_LITERAL_CSTRING("localhost");
     aAddressFamily = PR_AF_INET;
   }
 
   *aAddrInfo = nullptr;
-  nsresult rv = _GetAddrInfo_Portable(aHost, aAddressFamily, aFlags,
+  nsresult rv = _GetAddrInfo_Portable(host, aAddressFamily, aFlags,
                                       aAddrInfo);
 
 #ifdef DNSQUERY_AVAILABLE
   if (aGetTtl && NS_SUCCEEDED(rv)) {
     // Figure out the canonical name, or if that fails, just use the host name
     // we have.
-    const char *name = nullptr;
+    nsAutoCString name;
     if (*aAddrInfo != nullptr && !(*aAddrInfo)->mCanonicalName.IsEmpty()) {
-      name = (*aAddrInfo)->mCanonicalName.get();
+      name = (*aAddrInfo)->mCanonicalName;
     } else {
-      name = aHost;
+      name = host;
     }
 
-    LOG("Getting TTL for %s (cname = %s).", aHost, name);
+    LOG("Getting TTL for %s (cname = %s).", host.get(), name.get());
     uint32_t ttl = 0;
     nsresult ttlRv = _GetTTLData_Windows(name, &ttl, aAddressFamily);
     if (NS_SUCCEEDED(ttlRv)) {
       (*aAddrInfo)->ttl = ttl;
-      LOG("Got TTL %u for %s (name = %s).", ttl, aHost, name);
+      LOG("Got TTL %u for %s (name = %s).", ttl, host.get(), name.get());
     } else {
-      LOG_WARNING("Could not get TTL for %s (cname = %s).", aHost, name);
+      LOG_WARNING("Could not get TTL for %s (cname = %s).", host.get(), name.get());
     }
   }
 #endif
 
   return rv;
 }
 
 } // namespace net
--- a/netwerk/dns/GetAddrInfo.h
+++ b/netwerk/dns/GetAddrInfo.h
@@ -32,17 +32,17 @@ class AddrInfo;
  *     suppress the determination of the canonical name corresponding to
  *     hostname (PR_AI_NOCANONNAME will be ignored if the TTL is retrieved).
  * @param aAddrInfo[out] Will point to the results of the host lookup, or be
  *     null if the lookup failed.
  * @param aGetTtl[in] If true, the TTL will be retrieved if DNS provides the
  *     answers..
  */
 nsresult
-GetAddrInfo(const char* aHost, uint16_t aAddressFamily, uint16_t aFlags,
+GetAddrInfo(const nsACString& aHost, uint16_t aAddressFamily, uint16_t aFlags,
             AddrInfo** aAddrInfo, bool aGetTtl);
 
 /**
  * Initialize the GetAddrInfo module.
  *
  * GetAddrInfoShutdown() should be called for every time this function is
  * called.
  */
--- a/netwerk/dns/TRR.cpp
+++ b/netwerk/dns/TRR.cpp
@@ -389,17 +389,17 @@ TRR::ReceivePush(nsIHttpChannel *pushed,
   if (NS_FAILED(DohDecodeQuery(query, mHost, mType)) ||
       (PR_StringToNetAddr(mHost.get(), &tempAddr) == PR_SUCCESS)) { // literal
     LOG(("TRR::ReceivePush failed to decode %s\n", mHost.get()));
     return NS_ERROR_UNEXPECTED;
   }
 
   RefPtr<nsHostRecord> hostRecord;
   nsresult rv;
-  rv = mHostResolver->GetHostRecord(mHost.get(),
+  rv = mHostResolver->GetHostRecord(mHost,
                                     pushedRec->flags, pushedRec->af,
                                     pushedRec->pb,
                                     pushedRec->originSuffix,
                                     getter_AddRefs(hostRecord));
   if (NS_FAILED(rv)) {
     return rv;
   }
 
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -391,17 +391,17 @@ nsDNSAsyncRequest::SizeOfIncludingThis(M
 
     return n;
 }
 
 NS_IMETHODIMP
 nsDNSAsyncRequest::Cancel(nsresult reason)
 {
     NS_ENSURE_ARG(NS_FAILED(reason));
-    mResolver->DetachCallback(mHost.get(), mOriginAttributes, mFlags, mAF,
+    mResolver->DetachCallback(mHost, mOriginAttributes, mFlags, mAF,
                               this, reason);
     return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 
 class nsDNSSyncRequest
     : public nsResolveHostCallback
@@ -872,17 +872,17 @@ nsDNSService::AsyncResolveNative(const n
     uint16_t af = GetAFForLookup(hostname, flags);
 
     MOZ_ASSERT(listener);
     RefPtr<nsDNSAsyncRequest> req =
         new nsDNSAsyncRequest(res, hostname, aOriginAttributes, listener, flags, af);
     if (!req)
         return NS_ERROR_OUT_OF_MEMORY;
 
-    rv = res->ResolveHost(req->mHost.get(), req->mOriginAttributes, flags, af, req);
+    rv = res->ResolveHost(req->mHost, req->mOriginAttributes, flags, af, req);
     req.forget(result);
     return rv;
 }
 
 NS_IMETHODIMP
 nsDNSService::CancelAsyncResolve(const nsACString &aHostname,
                                  uint32_t          aFlags,
                                  nsIDNSListener   *aListener,
@@ -932,17 +932,17 @@ nsDNSService::CancelAsyncResolveNative(c
     nsCString hostname;
     nsresult rv = PreprocessHostname(localDomain, aHostname, idn, hostname);
     if (NS_FAILED(rv)) {
         return rv;
     }
 
     uint16_t af = GetAFForLookup(hostname, aFlags);
 
-    res->CancelAsyncRequest(hostname.get(), aOriginAttributes, aFlags, af,
+    res->CancelAsyncRequest(hostname, aOriginAttributes, aFlags, af,
                             aListener, aReason);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDNSService::Resolve(const nsACString  &aHostname,
                       uint32_t           flags,
                       JS::HandleValue    aOriginAttributes,
@@ -1032,17 +1032,17 @@ nsDNSService::ResolveInternal(const nsAC
     if (!mon)
         return NS_ERROR_OUT_OF_MEMORY;
 
     PR_EnterMonitor(mon);
     RefPtr<nsDNSSyncRequest> syncReq = new nsDNSSyncRequest(mon);
 
     uint16_t af = GetAFForLookup(hostname, flags);
 
-    rv = res->ResolveHost(hostname.get(), aOriginAttributes, flags, af, syncReq);
+    rv = res->ResolveHost(hostname, aOriginAttributes, flags, af, syncReq);
     if (NS_SUCCEEDED(rv)) {
         // wait for result
         while (!syncReq->mDone) {
             PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
         }
 
         if (NS_FAILED(syncReq->mStatus)) {
             rv = syncReq->mStatus;
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -702,23 +702,23 @@ nsHostResolver::Shutdown()
     {
         mozilla::DebugOnly<nsresult> rv = GetAddrInfoShutdown();
         NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                              "Failed to shutdown GetAddrInfo");
     }
 }
 
 nsresult
-nsHostResolver::GetHostRecord(const char *host,
+nsHostResolver::GetHostRecord(const nsACString &host,
                               uint16_t flags, uint16_t af, bool pb,
                               const nsCString &originSuffix,
                               nsHostRecord **result)
 {
     MutexAutoLock lock(mLock);
-    nsHostKey key(nsCString(host), flags, af, pb, originSuffix);
+    nsHostKey key(host, flags, af, pb, originSuffix);
 
     RefPtr<nsHostRecord>& entry = mRecordDB.GetOrInsert(key);
     if (!entry) {
         entry = new nsHostRecord(key);
     }
 
     RefPtr<nsHostRecord> rec = entry;
     if (rec->addr) {
@@ -727,31 +727,32 @@ nsHostResolver::GetHostRecord(const char
     if (rec->mResolving) {
         return NS_ERROR_FAILURE;
     }
     *result = rec.forget().take();
     return NS_OK;
 }
 
 nsresult
-nsHostResolver::ResolveHost(const char             *host,
+nsHostResolver::ResolveHost(const nsACString &aHost,
                             const OriginAttributes &aOriginAttributes,
                             uint16_t                flags,
                             uint16_t                af,
                             nsResolveHostCallback  *aCallback)
 {
-    NS_ENSURE_TRUE(host && *host, NS_ERROR_UNEXPECTED);
+    nsAutoCString host(aHost);
+    NS_ENSURE_TRUE(!host.IsEmpty(), NS_ERROR_UNEXPECTED);
 
-    LOG(("Resolving host [%s]%s%s.\n", host,
+    LOG(("Resolving host [%s]%s%s.\n", host.get(),
          flags & RES_BYPASS_CACHE ? " - bypassing cache" : "",
          flags & RES_REFRESH_CACHE ? " - refresh cache" : ""));
 
     // ensure that we are working with a valid hostname before proceeding.  see
     // bug 304904 for details.
-    if (!net_IsValidHostName(nsDependentCString(host)))
+    if (!net_IsValidHostName(host))
         return NS_ERROR_UNKNOWN_HOST;
 
     RefPtr<nsResolveHostCallback> callback(aCallback);
     // if result is set inside the lock, then we need to issue the
     // callback before returning.
     RefPtr<nsHostRecord> result;
     nsresult status = NS_OK, rv = NS_OK;
     {
@@ -770,96 +771,96 @@ nsHostResolver::ResolveHost(const char  
             // in the hash table.  if so, then check to see if we can't
             // just reuse the lookup result.  otherwise, if there are
             // any pending callbacks, then add to pending callbacks queue,
             // and return.  otherwise, add ourselves as first pending
             // callback, and proceed to do the lookup.
             nsAutoCString originSuffix;
             aOriginAttributes.CreateSuffix(originSuffix);
 
-            nsHostKey key(nsCString(host), flags, af,
+            nsHostKey key(host, flags, af,
                           (aOriginAttributes.mPrivateBrowsingId > 0),
                           originSuffix);
             RefPtr<nsHostRecord>& entry = mRecordDB.GetOrInsert(key);
             if (!entry) {
                 entry = new nsHostRecord(key);
             }
 
             RefPtr<nsHostRecord> rec = entry;
             MOZ_ASSERT(rec, "Record should not be null");
             if (!(flags & RES_BYPASS_CACHE) &&
                      rec->HasUsableResult(TimeStamp::NowLoRes(), flags)) {
-                LOG(("  Using cached record for host [%s].\n", host));
+                LOG(("  Using cached record for host [%s].\n", host.get()));
                 // put reference to host record on stack...
                 result = rec;
                 Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_HIT);
 
                 // For entries that are in the grace period
                 // or all cached negative entries, use the cache but start a new
                 // lookup in the background
                 ConditionallyRefreshRecord(rec, host);
 
                 if (rec->negative) {
-                    LOG(("  Negative cache entry for host [%s].\n", host));
+                    LOG(("  Negative cache entry for host [%s].\n", host.get()));
                     Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
                                           METHOD_NEGATIVE_HIT);
                     status = NS_ERROR_UNKNOWN_HOST;
                 }
             } else if (rec->addr) {
                 // if the host name is an IP address literal and has been parsed,
                 // go ahead and use it.
-                LOG(("  Using cached address for IP Literal [%s].\n", host));
+                LOG(("  Using cached address for IP Literal [%s].\n", host.get()));
                 Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
                                       METHOD_LITERAL);
                 result = rec;
-            } else if (PR_StringToNetAddr(host, &tempAddr) == PR_SUCCESS) {
+            } else if (PR_StringToNetAddr(host.get(), &tempAddr) == PR_SUCCESS) {
                 // try parsing the host name as an IP address literal to short
                 // circuit full host resolution.  (this is necessary on some
                 // platforms like Win9x.  see bug 219376 for more details.)
-                LOG(("  Host is IP Literal [%s].\n", host));
+                LOG(("  Host is IP Literal [%s].\n", host.get()));
                 // ok, just copy the result into the host record, and be done
                 // with it! ;-)
                 rec->addr = MakeUnique<NetAddr>();
                 PRNetAddrToNetAddr(&tempAddr, rec->addr.get());
                 // put reference to host record on stack...
                 Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
                                       METHOD_LITERAL);
                 result = rec;
             } else if (mPendingCount >= MAX_NON_PRIORITY_REQUESTS &&
                        !IsHighPriority(flags) &&
                        !rec->mResolving) {
                 LOG(("  Lookup queue full: dropping %s priority request for "
                      "host [%s].\n",
-                     IsMediumPriority(flags) ? "medium" : "low", host));
+                     IsMediumPriority(flags) ? "medium" : "low", host.get()));
                 Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
                                       METHOD_OVERFLOW);
                 // This is a lower priority request and we are swamped, so refuse it.
                 rv = NS_ERROR_DNS_LOOKUP_QUEUE_FULL;
             } else if (flags & RES_OFFLINE) {
-                LOG(("  Offline request for host [%s]; ignoring.\n", host));
+                LOG(("  Offline request for host [%s]; ignoring.\n", host.get()));
                 rv = NS_ERROR_OFFLINE;
             } else if (!rec->mResolving) {
                 // If this is an IPV4 or IPV6 specific request, check if there is
                 // an AF_UNSPEC entry we can use. Otherwise, hit the resolver...
 
                 if (!(flags & RES_BYPASS_CACHE) &&
                     ((af == PR_AF_INET) || (af == PR_AF_INET6))) {
                     // First, search for an entry with AF_UNSPEC
-                    const nsHostKey unspecKey(nsCString(host), flags, PR_AF_UNSPEC,
+                    const nsHostKey unspecKey(host, flags, PR_AF_UNSPEC,
                                               (aOriginAttributes.mPrivateBrowsingId > 0),
                                               originSuffix);
                     RefPtr<nsHostRecord> unspecRec = mRecordDB.Get(unspecKey);
 
                     TimeStamp now = TimeStamp::NowLoRes();
                     if (unspecRec && unspecRec->HasUsableResult(now, flags)) {
 
                         MOZ_ASSERT(unspecRec->addr_info || unspecRec->negative,
                                    "Entry should be resolved or negative.");
 
-                        LOG(("  Trying AF_UNSPEC entry for host [%s] af: %s.\n", host,
+                        LOG(("  Trying AF_UNSPEC entry for host [%s] af: %s.\n", host.get(),
                              (af == PR_AF_INET) ? "AF_INET" : "AF_INET6"));
 
                         // We need to lock in case any other thread is reading
                         // addr_info.
                         MutexAutoLock lock(rec->addr_info_lock);
 
                         // XXX: note that this actually leaks addr_info.
                         // For some reason, freeing the memory causes a crash in
@@ -901,58 +902,58 @@ nsHostResolver::ResolveHost(const char  
                                                   METHOD_HIT);
                             ConditionallyRefreshRecord(rec, host);
                         } else if (af == PR_AF_INET6) {
                             // For AF_INET6, a new lookup means another AF_UNSPEC
                             // lookup. We have already iterated through the
                             // AF_UNSPEC addresses, so we mark this record as
                             // negative.
                             LOG(("  No AF_INET6 in AF_UNSPEC entry: "
-                                 "host [%s] unknown host.", host));
+                                 "host [%s] unknown host.", host.get()));
                             result = rec;
                             rec->negative = true;
                             status = NS_ERROR_UNKNOWN_HOST;
                             Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
                                                   METHOD_NEGATIVE_HIT);
                         }
                     }
                 }
                 // If no valid address was found in the cache or this is an
                 // AF_UNSPEC request, then start a new lookup.
                 if (!result) {
-                    LOG(("  No usable address in cache for host [%s].", host));
+                    LOG(("  No usable address in cache for host [%s].", host.get()));
 
                     if (flags & RES_REFRESH_CACHE) {
                         rec->Invalidate();
                     }
 
                     // Add callback to the list of pending callbacks.
                     rec->mCallbacks.insertBack(callback);
                     rec->flags = flags;
                     rv = NameLookup(rec);
                     Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
                                           METHOD_NETWORK_FIRST);
                     if (NS_FAILED(rv) && callback->isInList()) {
                         callback->remove();
                     } else {
                         LOG(("  DNS lookup for host [%s] blocking "
                              "pending 'getaddrinfo' query: callback [%p]",
-                             host, callback.get()));
+                             host.get(), callback.get()));
                     }
                 }
             } else if (rec->mDidCallbacks) {
                 // record is still pending more (TRR) data; make the callback
                 // at once
                 result = rec;
                 // make it count as a hit
                 Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2, METHOD_HIT);
-                LOG(("  Host [%s] re-using early TRR resolve data\n", host));
+                LOG(("  Host [%s] re-using early TRR resolve data\n", host.get()));
             } else {
                 LOG(("  Host [%s] is being resolved. Appending callback "
-                     "[%p].", host, callback.get()));
+                     "[%p].", host.get(), callback.get()));
 
                 rec->mCallbacks.insertBack(callback);
                 if (rec->onQueue) {
                     Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
                                           METHOD_NETWORK_SHARED);
 
                     // Consider the case where we are on a pending queue of
                     // lower priority than the request is being made at.
@@ -986,33 +987,33 @@ nsHostResolver::ResolveHost(const char  
         }
         callback->OnResolveHostComplete(this, result, status);
     }
 
     return rv;
 }
 
 void
-nsHostResolver::DetachCallback(const char             *host,
+nsHostResolver::DetachCallback(const nsACString &host,
                                const OriginAttributes &aOriginAttributes,
                                uint16_t                flags,
                                uint16_t                af,
                                nsResolveHostCallback  *aCallback,
                                nsresult                status)
 {
     RefPtr<nsHostRecord> rec;
     RefPtr<nsResolveHostCallback> callback(aCallback);
 
     {
         MutexAutoLock lock(mLock);
 
         nsAutoCString originSuffix;
         aOriginAttributes.CreateSuffix(originSuffix);
 
-        nsHostKey key(nsCString(host), flags, af,
+        nsHostKey key(host, flags, af,
                       (aOriginAttributes.mPrivateBrowsingId > 0),
                       originSuffix);
         RefPtr<nsHostRecord> entry = mRecordDB.Get(key);
         if (entry) {
             // walk list looking for |callback|... we cannot assume
             // that it will be there!
 
             for (nsResolveHostCallback* c: entry->mCallbacks) {
@@ -1261,22 +1262,22 @@ nsHostResolver::NameLookup(nsHostRecord 
         ((mode == MODE_TRRFIRST) && NS_FAILED(rv))) {
         rv = NativeLookup(rec);
     }
 
     return rv;
 }
 
 nsresult
-nsHostResolver::ConditionallyRefreshRecord(nsHostRecord *rec, const char *host)
+nsHostResolver::ConditionallyRefreshRecord(nsHostRecord *rec, const nsACString &host)
 {
     if ((rec->CheckExpiration(TimeStamp::NowLoRes()) != nsHostRecord::EXP_VALID
             || rec->negative) && !rec->mResolving) {
         LOG(("  Using %s cache entry for host [%s] but starting async renewal.",
-            rec->negative ? "negative" :"positive", host));
+            rec->negative ? "negative" :"positive", host.BeginReading()));
         NameLookup(rec);
 
         if (!rec->negative) {
             // negative entries are constantly being refreshed, only
             // track positive grace period induced renewals
             Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
                 METHOD_RENEWAL);
         }
@@ -1699,32 +1700,32 @@ nsHostResolver::CompleteLookup(nsHostRec
             NS_SUCCEEDED(rv),
             "Could not issue second async lookup for TTL.");
     }
 #endif
     return LOOKUP_OK;
 }
 
 void
-nsHostResolver::CancelAsyncRequest(const char             *host,
+nsHostResolver::CancelAsyncRequest(const nsACString &host,
                                    const OriginAttributes &aOriginAttributes,
                                    uint16_t                flags,
                                    uint16_t                af,
                                    nsIDNSListener         *aListener,
                                    nsresult                status)
 
 {
     MutexAutoLock lock(mLock);
 
     nsAutoCString originSuffix;
     aOriginAttributes.CreateSuffix(originSuffix);
 
     // Lookup the host record associated with host, flags & address family
 
-    nsHostKey key(nsCString(host), flags, af,
+    nsHostKey key(host, flags, af,
                   (aOriginAttributes.mPrivateBrowsingId > 0),
                   originSuffix);
     RefPtr<nsHostRecord> rec = mRecordDB.Get(key);
     if (rec) {
         nsHostRecord* recPtr = nullptr;
 
         for (RefPtr<nsResolveHostCallback> c : rec->mCallbacks) {
             if (c->EqualsAsyncListener(aListener)) {
@@ -1796,22 +1797,22 @@ nsHostResolver::ThreadFunc(void *arg)
             rec.swap(tmpRec);
         }
 
         LOG(("DNS lookup thread - Calling getaddrinfo for host [%s].\n",
              rec->host.get()));
         
         TimeStamp startTime = TimeStamp::Now();
         bool getTtl = rec->mGetTtl;
-        nsresult status = GetAddrInfo(rec->host.get(), rec->af,
+        nsresult status = GetAddrInfo(rec->host, rec->af,
                                       rec->flags, &ai,
                                       getTtl);
 #if defined(RES_RETRY_ON_FAILURE)
         if (NS_FAILED(status) && rs.Reset()) {
-            status = GetAddrInfo(rec->host.get(), rec->af,
+            status = GetAddrInfo(rec->host, rec->af,
                                  rec->flags, &ai, getTtl);
         }
 #endif
 
         {   // obtain lock to check shutdown and manage inter-module telemetry
             MutexAutoLock lock(resolver->mLock);
 
             if (!resolver->mShutdown) {
--- a/netwerk/dns/nsHostResolver.h
+++ b/netwerk/dns/nsHostResolver.h
@@ -272,17 +272,17 @@ public:
     NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
 
      enum LookupStatus {
         LOOKUP_OK,
         LOOKUP_RESOLVEAGAIN,
     };
 
     virtual LookupStatus CompleteLookup(nsHostRecord *, nsresult, mozilla::net::AddrInfo *, bool pb) = 0;
-    virtual nsresult GetHostRecord(const char *host,
+    virtual nsresult GetHostRecord(const nsACString &host,
                                    uint16_t flags, uint16_t af, bool pb,
                                    const nsCString &originSuffix,
                                    nsHostRecord **result)
     {
         return NS_ERROR_FAILURE;
     }
     virtual nsresult TrrLookup_unlocked(nsHostRecord *, mozilla::net::TRR *pushedTRR = nullptr)
     {
@@ -324,43 +324,43 @@ public:
 
     /**
      * resolve the given hostname and originAttributes asynchronously.  the caller
      * can synthesize a synchronous host lookup using a lock and a cvar.  as noted
      * above the callback will occur re-entrantly from an unspecified thread.  the
      * host lookup cannot be canceled (cancelation can be layered above this by
      * having the callback implementation return without doing anything).
      */
-    nsresult ResolveHost(const char                      *hostname,
+    nsresult ResolveHost(const nsACString &hostname,
                          const mozilla::OriginAttributes &aOriginAttributes,
                          uint16_t                         flags,
                          uint16_t                         af,
                          nsResolveHostCallback           *callback);
 
     /**
      * removes the specified callback from the nsHostRecord for the given
      * hostname, originAttributes, flags, and address family.  these parameters
      * should correspond to the parameters passed to ResolveHost.  this function
      * executes the callback if the callback is still pending with the given status.
      */
-    void DetachCallback(const char                      *hostname,
+    void DetachCallback(const nsACString &hostname,
                         const mozilla::OriginAttributes &aOriginAttributes,
                         uint16_t                         flags,
                         uint16_t                         af,
                         nsResolveHostCallback           *callback,
                         nsresult                         status);
 
     /**
      * Cancels an async request associated with the hostname, originAttributes, flags,
      * address family and listener.  Cancels first callback found which matches
      * these criteria.  These parameters should correspond to the parameters
      * passed to ResolveHost.  If this is the last callback associated with the
      * host record, it is removed from any request queues it might be on.
      */
-    void CancelAsyncRequest(const char                      *host,
+    void CancelAsyncRequest(const nsACString &host,
                             const mozilla::OriginAttributes &aOriginAttributes,
                             uint16_t                         flags,
                             uint16_t                         af,
                             nsIDNSListener                  *aListener,
                             nsresult                         status);
     /**
      * values for the flags parameter passed to ResolveHost and DetachCallback
      * that may be bitwise OR'd together.
@@ -385,17 +385,17 @@ public:
     size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
 
     /**
      * Flush the DNS cache.
      */
     void FlushCache();
 
     LookupStatus CompleteLookup(nsHostRecord *, nsresult, mozilla::net::AddrInfo *, bool pb) override;
-    nsresult GetHostRecord(const char *host,
+    nsresult GetHostRecord(const nsACString &host,
                            uint16_t flags, uint16_t af, bool pb,
                            const nsCString &originSuffix,
                            nsHostRecord **result) override;
     nsresult TrrLookup_unlocked(nsHostRecord *, mozilla::net::TRR *pushedTRR = nullptr) override;
 
 private:
    explicit nsHostResolver(uint32_t maxCacheEntries,
                            uint32_t defaultCacheEntryLifetime,
@@ -420,17 +420,17 @@ private:
     // calls CompleteLookup with the NS_ERROR_ABORT result code.
     void     ClearPendingQueue(mozilla::LinkedList<RefPtr<nsHostRecord>>& aPendingQ);
     nsresult ConditionallyCreateThread(nsHostRecord *rec);
 
     /**
      * Starts a new lookup in the background for entries that are in the grace
      * period with a failed connect or all cached entries are negative.
      */
-    nsresult ConditionallyRefreshRecord(nsHostRecord *rec, const char *host);
+    nsresult ConditionallyRefreshRecord(nsHostRecord *rec, const nsACString &host);
 
     static void ThreadFunc(void *);
 
     enum {
         METHOD_HIT = 1,
         METHOD_RENEWAL = 2,
         METHOD_NEGATIVE_HIT = 3,
         METHOD_LITERAL = 4,