Bug 1332202 - Convert most infallible NS_EscapeURL calls to fallible version. r=froydnj, a=lizzard
authorEric Rahm <erahm@mozilla.com>
Tue, 24 Jan 2017 11:11:44 -0800
changeset 375712 34591732740b9e4d486fad035f677cde7584a6fc
parent 375711 f370610ec22eca47fba979f2668ab330fac5eb4f
child 375713 c142accc407019f2d8ab1be22dd872bf84a1527d
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, lizzard
bugs1332202
milestone53.0a2
Bug 1332202 - Convert most infallible NS_EscapeURL calls to fallible version. r=froydnj, a=lizzard This makes most users of |NS_EscapeURL| use the fallible version. A few are left infallible as it seems like the entire function is assumed to be infallible. MozReview-Commit-ID: Cy1L5jQwjO1
caps/nsNullPrincipalURI.cpp
dom/html/HTMLFormSubmission.cpp
dom/jsurl/nsJSProtocolHandler.cpp
dom/quota/ActorsParent.cpp
dom/storage/StorageObserver.cpp
dom/webbrowserpersist/nsWebBrowserPersist.cpp
netwerk/base/nsSimpleURI.cpp
netwerk/base/nsStandardURL.cpp
netwerk/base/nsURLHelperUnix.cpp
netwerk/protocol/http/nsHttpDigestAuth.cpp
--- a/caps/nsNullPrincipalURI.cpp
+++ b/caps/nsNullPrincipalURI.cpp
@@ -93,16 +93,18 @@ nsNullPrincipalURI::GetAsciiHostPort(nsA
 }
 
 NS_IMETHODIMP
 nsNullPrincipalURI::GetAsciiSpec(nsACString &_spec)
 {
   nsAutoCString buffer;
   // Ignore the return value -- nsNullPrincipalURI::GetSpec() is infallible.
   Unused << GetSpec(buffer);
+  // This uses the infallible version of |NS_EscapeURL| as |GetSpec| is
+  // already infallible.
   NS_EscapeURL(buffer, esc_OnlyNonASCII | esc_AlwaysCopy, _spec);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNullPrincipalURI::GetHost(nsACString &_host)
 {
   _host.Truncate();
--- a/dom/html/HTMLFormSubmission.cpp
+++ b/dom/html/HTMLFormSubmission.cpp
@@ -277,18 +277,22 @@ HandleMailtoSubject(nsCString& aPath)
                                            nsContentUtils::eFORMS_PROPERTIES,
                                            "DefaultFormSubject",
                                            formatStrings,
                                            subjectStr);
     if (NS_FAILED(rv))
       return;
     aPath.AppendLiteral("subject=");
     nsCString subjectStrEscaped;
-    aPath.Append(NS_EscapeURL(NS_ConvertUTF16toUTF8(subjectStr), esc_Query,
-                              subjectStrEscaped));
+    rv = NS_EscapeURL(NS_ConvertUTF16toUTF8(subjectStr), esc_Query,
+                      subjectStrEscaped, mozilla::fallible);
+    if (NS_FAILED(rv))
+      return;
+
+    aPath.Append(subjectStrEscaped);
   }
 }
 
 nsresult
 FSURLEncoded::GetEncodedSubmission(nsIURI* aURI,
                                    nsIInputStream** aPostDataStream)
 {
   nsresult rv = NS_OK;
--- a/dom/jsurl/nsJSProtocolHandler.cpp
+++ b/dom/jsurl/nsJSProtocolHandler.cpp
@@ -1140,18 +1140,22 @@ nsJSProtocolHandler::EnsureUTF8Spec(cons
   if (!mTextToSubURI) {
     mTextToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   nsAutoString uStr;
   rv = mTextToSubURI->UnEscapeNonAsciiURI(nsDependentCString(aCharset), aSpec, uStr);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (!IsASCII(uStr))
-    NS_EscapeURL(NS_ConvertUTF16toUTF8(uStr), esc_AlwaysCopy | esc_OnlyNonASCII, aUTF8Spec);
+  if (!IsASCII(uStr)) {
+    rv = NS_EscapeURL(NS_ConvertUTF16toUTF8(uStr),
+                      esc_AlwaysCopy | esc_OnlyNonASCII, aUTF8Spec,
+                      mozilla::fallible);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIProtocolHandler methods:
 
 NS_IMETHODIMP
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -3391,21 +3391,23 @@ QuotaManager::GetQuotaObject(Persistence
     rv = aFile->GetFileSize(&fileSize);
     NS_ENSURE_SUCCESS(rv, nullptr);
   }
   else {
     fileSize = 0;
   }
 
   // Re-escape our parameters above to make sure we get the right quota group.
-  nsAutoCString tempStorage1;
-  const nsCSubstring& group = NS_EscapeURL(aGroup, esc_Query, tempStorage1);
-
-  nsAutoCString tempStorage2;
-  const nsCSubstring& origin = NS_EscapeURL(aOrigin, esc_Query, tempStorage2);
+  nsAutoCString group;
+  rv = NS_EscapeURL(aGroup, esc_Query, group, fallible);
+  NS_ENSURE_SUCCESS(rv, nullptr);
+
+  nsAutoCString origin;
+  rv = NS_EscapeURL(aOrigin, esc_Query, origin, fallible);
+  NS_ENSURE_SUCCESS(rv, nullptr);
 
   RefPtr<QuotaObject> result;
   {
     MutexAutoLock lock(mQuotaMutex);
 
     GroupInfoPair* pair;
     if (!mGroupInfoPairs.Get(group, &pair)) {
       return nullptr;
--- a/dom/storage/StorageObserver.cpp
+++ b/dom/storage/StorageObserver.cpp
@@ -259,19 +259,21 @@ StorageObserver::Observe(nsISupports* aS
     nsAutoCString aceDomain;
     nsCOMPtr<nsIIDNService> converter = do_GetService(NS_IDNSERVICE_CONTRACTID);
     if (converter) {
       rv = converter->ConvertUTF8toACE(NS_ConvertUTF16toUTF8(aData), aceDomain);
       NS_ENSURE_SUCCESS(rv, rv);
     } else {
       // In case the IDN service is not available, this is the best we can come
       // up with!
-      NS_EscapeURL(NS_ConvertUTF16toUTF8(aData),
-                   esc_OnlyNonASCII | esc_AlwaysCopy,
-                   aceDomain);
+      rv = NS_EscapeURL(NS_ConvertUTF16toUTF8(aData),
+                        esc_OnlyNonASCII | esc_AlwaysCopy,
+                        aceDomain,
+                        fallible);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     nsAutoCString originScope;
     rv = CreateReversedDomain(aceDomain, originScope);
     NS_ENSURE_SUCCESS(rv, rv);
 
     StorageDBBridge* db = StorageCache::StartDatabase();
     NS_ENSURE_TRUE(db, NS_ERROR_FAILURE);
--- a/dom/webbrowserpersist/nsWebBrowserPersist.cpp
+++ b/dom/webbrowserpersist/nsWebBrowserPersist.cpp
@@ -2541,18 +2541,18 @@ nsWebBrowserPersist::URIData::GetLocalUR
             }
             
             nsAutoCString filename;
             url->GetFileName(filename);
             
             nsAutoCString rawPathURL(mRelativePathToData);
             rawPathURL.Append(filename);
             
-            nsAutoCString buf;
-            aSpecOut = NS_EscapeURL(rawPathURL, esc_FilePath, buf);
+            rv = NS_EscapeURL(rawPathURL, esc_FilePath, aSpecOut, fallible);
+            NS_ENSURE_SUCCESS(rv, rv);
         } else {
             nsAutoCString rawPathURL;
             
             nsCOMPtr<nsIFile> dataFile;
             rv = GetLocalFileFromURI(mFile, getter_AddRefs(dataFile));
             NS_ENSURE_SUCCESS(rv, rv);
             
             nsCOMPtr<nsIFile> docFile;
@@ -2561,18 +2561,18 @@ nsWebBrowserPersist::URIData::GetLocalUR
             
             nsCOMPtr<nsIFile> parentDir;
             rv = docFile->GetParent(getter_AddRefs(parentDir));
             NS_ENSURE_SUCCESS(rv, rv);
             
             rv = dataFile->GetRelativePath(parentDir, rawPathURL);
             NS_ENSURE_SUCCESS(rv, rv);
             
-            nsAutoCString buf;
-            aSpecOut = NS_EscapeURL(rawPathURL, esc_FilePath, buf);
+            rv = NS_EscapeURL(rawPathURL, esc_FilePath, aSpecOut, fallible);
+            NS_ENSURE_SUCCESS(rv, rv);
         }
     } else {
         fileAsURI->GetSpec(aSpecOut);
     }
     if (mIsSubFrame) {
         AppendUTF16toUTF8(mSubFrameExt, aSpecOut);
     }
 
--- a/netwerk/base/nsSimpleURI.cpp
+++ b/netwerk/base/nsSimpleURI.cpp
@@ -655,18 +655,17 @@ nsSimpleURI::Resolve(const nsACString &r
 }
 
 NS_IMETHODIMP
 nsSimpleURI::GetAsciiSpec(nsACString &result)
 {
     nsAutoCString buf;
     nsresult rv = GetSpec(buf);
     if (NS_FAILED(rv)) return rv;
-    NS_EscapeURL(buf, esc_OnlyNonASCII|esc_AlwaysCopy, result);
-    return NS_OK;
+    return NS_EscapeURL(buf, esc_OnlyNonASCII|esc_AlwaysCopy, result, fallible);
 }
 
 NS_IMETHODIMP
 nsSimpleURI::GetAsciiHostPort(nsACString &result)
 {
     // XXX This behavior mimics GetHostPort.
     return NS_ERROR_FAILURE;
 }
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1386,23 +1386,27 @@ nsStandardURL::GetAsciiSpec(nsACString &
         return NS_OK;
     }
 
     // try to guess the capacity required for result...
     result.SetCapacity(mSpec.Length() + std::min<uint32_t>(32, mSpec.Length()/10));
 
     result = Substring(mSpec, 0, mScheme.mLen + 3);
 
+    // This is left fallible as this entire function is expected to be
+    // infallible.
     NS_EscapeURL(Userpass(true), esc_OnlyNonASCII | esc_AlwaysCopy, result);
 
     // get the hostport
     nsAutoCString hostport;
     MOZ_ALWAYS_SUCCEEDS(GetAsciiHostPort(hostport));
     result += hostport;
 
+    // This is left fallible as this entire function is expected to be
+    // infallible.
     NS_EscapeURL(Path(), esc_OnlyNonASCII | esc_AlwaysCopy, result);
     CALL_RUST_GETTER_STR(result, GetAsciiSpec, result);
     return NS_OK;
 }
 
 // result is ASCII
 NS_IMETHODIMP
 nsStandardURL::GetAsciiHostPort(nsACString &result)
--- a/netwerk/base/nsURLHelperUnix.cpp
+++ b/netwerk/base/nsURLHelperUnix.cpp
@@ -60,23 +60,34 @@ net_GetFileFromURLSpec(const nsACString 
     if (NS_FAILED(rv))
       return rv;
     
     nsAutoCString directory, fileBaseName, fileExtension, path;
 
     rv = net_ParseFileURL(aURL, directory, fileBaseName, fileExtension);
     if (NS_FAILED(rv)) return rv;
 
-    if (!directory.IsEmpty())
-        NS_EscapeURL(directory, esc_Directory|esc_AlwaysCopy, path);
-    if (!fileBaseName.IsEmpty())
-        NS_EscapeURL(fileBaseName, esc_FileBaseName|esc_AlwaysCopy, path);
+    if (!directory.IsEmpty()) {
+        rv = NS_EscapeURL(directory, esc_Directory|esc_AlwaysCopy, path,
+                         mozilla::fallible);
+        if (NS_FAILED(rv))
+          return rv;
+    }
+    if (!fileBaseName.IsEmpty()) {
+        rv = NS_EscapeURL(fileBaseName, esc_FileBaseName|esc_AlwaysCopy, path,
+                          mozilla::fallible);
+        if (NS_FAILED(rv))
+          return rv;
+    }
     if (!fileExtension.IsEmpty()) {
         path += '.';
-        NS_EscapeURL(fileExtension, esc_FileExtension|esc_AlwaysCopy, path);
+        rv = NS_EscapeURL(fileExtension, esc_FileExtension|esc_AlwaysCopy, path,
+                          mozilla::fallible);
+        if (NS_FAILED(rv))
+          return rv;
     }
     
     NS_UnescapeURL(path);
     if (path.Length() != strlen(path.get()))
         return NS_ERROR_FILE_INVALID_PATH;
 
     if (IsUTF8(path)) {
         // speed up the start-up where UTF-8 is the native charset
--- a/netwerk/protocol/http/nsHttpDigestAuth.cpp
+++ b/netwerk/protocol/http/nsHttpDigestAuth.cpp
@@ -116,17 +116,20 @@ nsHttpDigestAuth::GetMethodAndPath(nsIHt
           //
           // make sure we escape any UTF-8 characters in the URI path.  the
           // digest auth uri attribute needs to match the request-URI.
           //
           // XXX we should really ask the HTTP channel for this string
           // instead of regenerating it here.
           //
           nsAutoCString buf;
-          path = NS_EscapeURL(path, esc_OnlyNonASCII, buf);
+          rv = NS_EscapeURL(path, esc_OnlyNonASCII, buf, mozilla::fallible);
+          if (NS_SUCCEEDED(rv)) {
+            path = buf;
+          }
         }
       }
     }
   }
   return rv;
 }
 
 //-----------------------------------------------------------------------------