Bug 1297300 - Add missing checks to GetSpec() calls in toolkit/. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 08 Sep 2016 14:32:20 +1000
changeset 313378 d8fd0a41c62f7a22a2c288f0eda2174166a22e56
parent 313377 f0e7ef6f72894a499815393b6270fbbf088c19ad
child 313379 d008348cd4f450faf68fdeba7ca2d8146ddce83a
push id30679
push usercbook@mozilla.com
push dateFri, 09 Sep 2016 10:03:06 +0000
treeherdermozilla-central@feff79e5b137 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1297300
milestone51.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 1297300 - Add missing checks to GetSpec() calls in toolkit/. r=froydnj.
toolkit/components/commandlines/nsCommandLine.cpp
toolkit/components/downloads/nsDownloadManager.cpp
toolkit/components/jsdownloads/src/DownloadPlatform.cpp
toolkit/mozapps/extensions/AddonContentPolicy.cpp
toolkit/system/gnome/nsGIOService.cpp
--- a/toolkit/components/commandlines/nsCommandLine.cpp
+++ b/toolkit/components/commandlines/nsCommandLine.cpp
@@ -60,17 +60,17 @@ protected:
   typedef nsresult (*EnumerateHandlersCallback)(nsICommandLineHandler* aHandler,
 					nsICommandLine* aThis,
 					void *aClosure);
   typedef nsresult (*EnumerateValidatorsCallback)(nsICommandLineValidator* aValidator,
 					nsICommandLine* aThis,
 					void *aClosure);
 
   void appendArg(const char* arg);
-  void resolveShortcutURL(nsIFile* aFile, nsACString& outURL);
+  MOZ_MUST_USE nsresult resolveShortcutURL(nsIFile* aFile, nsACString& outURL);
   nsresult EnumerateHandlers(EnumerateHandlersCallback aCallback, void *aClosure);
   nsresult EnumerateValidators(EnumerateValidatorsCallback aCallback, void *aClosure);
 
   nsTArray<nsString>      mArgs;
   uint32_t                mState;
   nsCOMPtr<nsIFile>       mWorkingDir;
   nsCOMPtr<nsIDOMWindow>  mWindowContext;
   bool                    mPreventDefault;
@@ -360,18 +360,18 @@ nsCommandLine::ResolveURI(const nsAStrin
   }
 
   nsCOMPtr<nsIFile> lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
   rv = lf->InitWithPath(aArgument);
   if (NS_SUCCEEDED(rv)) {
     lf->Normalize();
     nsAutoCString url;
     // Try to resolve the url for .url files.
-    resolveShortcutURL(lf, url);
-    if (!url.IsEmpty()) {
+    rv = resolveShortcutURL(lf, url);
+    if (NS_SUCCEEDED(rv) && !url.IsEmpty()) {
       return io->NewURI(url,
                         nullptr,
                         workingDirURI,
                         aResult);
     }
 
     return io->NewFileURI(lf, aResult);
   }
@@ -394,30 +394,30 @@ nsCommandLine::appendArg(const char* arg
   CopyUTF8toUTF16(nsDependentCString(arg), warg);
 #else
   NS_CopyNativeToUnicode(nsDependentCString(arg), warg);
 #endif
 
   mArgs.AppendElement(warg);
 }
 
-void
+nsresult
 nsCommandLine::resolveShortcutURL(nsIFile* aFile, nsACString& outURL)
 {
   nsCOMPtr<nsIFileProtocolHandler> fph;
   nsresult rv = NS_GetFileProtocolHandler(getter_AddRefs(fph));
   if (NS_FAILED(rv))
-    return;
+    return rv;
 
   nsCOMPtr<nsIURI> uri;
   rv = fph->ReadURLFile(aFile, getter_AddRefs(uri));
   if (NS_FAILED(rv))
-    return;
+    return rv;
 
-  uri->GetSpec(outURL);
+  return uri->GetSpec(outURL);
 }
 
 NS_IMETHODIMP
 nsCommandLine::Init(int32_t argc, const char* const* argv, nsIFile* aWorkingDir,
                     uint32_t aState)
 {
   NS_ENSURE_ARG_MAX(aState, 2);
 
--- a/toolkit/components/downloads/nsDownloadManager.cpp
+++ b/toolkit/components/downloads/nsDownloadManager.cpp
@@ -1590,18 +1590,20 @@ nsDownloadManager::AddDownload(DownloadT
   dl->mMIMEInfo = aMIMEInfo;
   dl->SetStartTime(aStartTime == 0 ? PR_Now() : aStartTime);
 
   // Creates a cycle that will be broken when the download finishes
   dl->mCancelable = aCancelable;
 
   // Adding to the DB
   nsAutoCString source, target;
-  aSource->GetSpec(source);
-  aTarget->GetSpec(target);
+  rv = aSource->GetSpec(source);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = aTarget->GetSpec(target);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Track the temp file for exthandler downloads
   nsAutoString tempPath;
   if (aTempFile)
     aTempFile->GetPath(tempPath);
 
   // Break down MIMEInfo but don't panic if we can't get all the pieces - we
   // can still download the file
@@ -2810,17 +2812,18 @@ nsDownload::SetState(DownloadState aStat
             }
 #endif
           }
 #endif
 #ifdef MOZ_ENABLE_GIO
           // Use GIO to store the source URI for later display in the file manager.
           GFile* gio_file = g_file_new_for_path(NS_ConvertUTF16toUTF8(path).get());
           nsCString source_uri;
-          mSource->GetSpec(source_uri);
+          rv = mSource->GetSpec(source_uri);
+          NS_ENSURE_SUCCESS(rv, rv);
           GFileInfo *file_info = g_file_info_new();
           g_file_info_set_attribute_string(file_info, "metadata::download-uri", source_uri.get());
           g_file_set_attributes_async(gio_file,
                                       file_info,
                                       G_FILE_QUERY_INFO_NONE,
                                       G_PRIORITY_DEFAULT,
                                       nullptr, gio_set_metadata_done, nullptr);
           g_object_unref(file_info);
--- a/toolkit/components/jsdownloads/src/DownloadPlatform.cpp
+++ b/toolkit/components/jsdownloads/src/DownloadPlatform.cpp
@@ -101,17 +101,18 @@ nsresult DownloadPlatform::DownloadDone(
         }
 #endif
       }
 #endif
 #ifdef MOZ_ENABLE_GIO
       // Use GIO to store the source URI for later display in the file manager.
       GFile* gio_file = g_file_new_for_path(NS_ConvertUTF16toUTF8(path).get());
       nsCString source_uri;
-      aSource->GetSpec(source_uri);
+      nsresult rv = aSource->GetSpec(source_uri);
+      NS_ENSURE_SUCCESS(rv, rv);
       GFileInfo *file_info = g_file_info_new();
       g_file_info_set_attribute_string(file_info, "metadata::download-uri", source_uri.get());
       g_file_set_attributes_async(gio_file,
                                   file_info,
                                   G_FILE_QUERY_INFO_NONE,
                                   G_PRIORITY_DEFAULT,
                                   nullptr, gio_set_metadata_done, nullptr);
       g_object_unref(file_info);
--- a/toolkit/mozapps/extensions/AddonContentPolicy.cpp
+++ b/toolkit/mozapps/extensions/AddonContentPolicy.cpp
@@ -67,26 +67,25 @@ GetWindowIDFromContext(nsISupports* aCon
 
 static nsresult
 LogMessage(const nsAString &aMessage, nsIURI* aSourceURI, const nsAString &aSourceSample,
            nsISupports* aContext)
 {
   nsCOMPtr<nsIScriptError> error = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
   NS_ENSURE_TRUE(error, NS_ERROR_OUT_OF_MEMORY);
 
-  nsAutoCString sourceName;
-  nsresult rv = aSourceURI->GetSpec(sourceName);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCString sourceName = aSourceURI->GetSpecOrDefault();
 
   uint64_t windowID = 0;
   GetWindowIDFromContext(aContext, &windowID);
 
-  rv = error->InitWithWindowID(aMessage, NS_ConvertUTF8toUTF16(sourceName),
-                               aSourceSample, 0, 0, nsIScriptError::errorFlag,
-                               "JavaScript", windowID);
+  nsresult rv =
+    error->InitWithWindowID(aMessage, NS_ConvertUTF8toUTF16(sourceName),
+                            aSourceSample, 0, 0, nsIScriptError::errorFlag,
+                            "JavaScript", windowID);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIConsoleService> console = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
   NS_ENSURE_TRUE(console, NS_ERROR_OUT_OF_MEMORY);
 
   console->LogMessage(error);
   return NS_OK;
 }
--- a/toolkit/system/gnome/nsGIOService.cpp
+++ b/toolkit/system/gnome/nsGIOService.cpp
@@ -325,17 +325,18 @@ nsGIOService::GetDescriptionForMimeType(
   g_free(desc);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGIOService::ShowURI(nsIURI* aURI)
 {
   nsAutoCString spec;
-  aURI->GetSpec(spec);
+  nsresult rv = aURI->GetSpec(spec);
+  NS_ENSURE_SUCCESS(rv, rv);
   GError *error = nullptr;
   if (!g_app_info_launch_default_for_uri(spec.get(), nullptr, &error)) {
     g_warning("Could not launch default application for URI: %s", error->message);
     g_error_free(error);
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }