Bug 1026022 - Check that string is UTF8. r=mcmanus, a=sledru
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 07 Jul 2014 14:07:27 -0400
changeset 208775 8825a5c848a25fe75408ec68bf620a589d425ba4
parent 208774 05069bac98d803608a74b469c71463a6ddb9f1eb
child 208776 fad78d49fe076822234a0f6391ec5a424a413a4f
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, sledru
bugs1026022
milestone32.0a2
Bug 1026022 - Check that string is UTF8. r=mcmanus, a=sledru
netwerk/dns/nsDNSService2.cpp
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -677,18 +677,22 @@ nsDNSService::AsyncResolve(const nsACStr
 
     if (localDomain) {
         hostPtr = &(NS_LITERAL_CSTRING("localhost"));
     }
 
     nsresult rv;
     nsAutoCString hostACE;
     if (idn && !IsASCII(*hostPtr)) {
-        if (NS_SUCCEEDED(idn->ConvertUTF8toACE(*hostPtr, hostACE)))
+        if (IsUTF8(*hostPtr) &&
+            NS_SUCCEEDED(idn->ConvertUTF8toACE(*hostPtr, hostACE))) {
             hostPtr = &hostACE;
+        } else {
+            return NS_ERROR_FAILURE;
+        }
     }
 
     // make sure JS callers get notification on the main thread
     nsCOMPtr<nsIXPConnectWrappedJS> wrappedListener = do_QueryInterface(listener);
     if (wrappedListener && !target) {
         nsCOMPtr<nsIThread> mainThread;
         NS_GetMainThread(getter_AddRefs(mainThread));
         target = do_QueryInterface(mainThread);
@@ -740,18 +744,22 @@ nsDNSService::CancelAsyncResolve(const n
     }
     if (!res)
         return NS_ERROR_OFFLINE;
 
     nsCString hostname(aHostname);
 
     nsAutoCString hostACE;
     if (idn && !IsASCII(aHostname)) {
-        if (NS_SUCCEEDED(idn->ConvertUTF8toACE(aHostname, hostACE)))
+        if (IsUTF8(aHostname) &&
+            NS_SUCCEEDED(idn->ConvertUTF8toACE(aHostname, hostACE))) {
             hostname = hostACE;
+        } else {
+            return NS_ERROR_FAILURE;
+        }
     }
 
     uint16_t af = GetAFForLookup(hostname, aFlags);
 
     res->CancelAsyncRequest(hostname.get(), aFlags, af, aListener, aReason);
     return NS_OK;
 }
 
@@ -786,18 +794,22 @@ nsDNSService::Resolve(const nsACString &
 
     if (localDomain) {
         hostPtr = &(NS_LITERAL_CSTRING("localhost"));
     }
 
     nsresult rv;
     nsAutoCString hostACE;
     if (idn && !IsASCII(*hostPtr)) {
-        if (NS_SUCCEEDED(idn->ConvertUTF8toACE(*hostPtr, hostACE)))
+        if (IsUTF8(*hostPtr) &&
+            NS_SUCCEEDED(idn->ConvertUTF8toACE(*hostPtr, hostACE))) {
             hostPtr = &hostACE;
+        } else {
+            return NS_ERROR_FAILURE;
+        }
     }
 
     //
     // sync resolve: since the host resolver only works asynchronously, we need
     // to use a mutex and a condvar to wait for the result.  however, since the
     // result may be in the resolvers cache, we might get called back recursively
     // on the same thread.  so, our mutex needs to be re-entrant.  in other words,
     // we need to use a monitor! ;-)