Bug 1301706 - Check return value of nsIURI::GetSpec. r=mkmelin
authorJorg K <jorgk@jorgk.com>
Sat, 10 Sep 2016 19:07:02 +0200
changeset 25918 33b093acd0a625a6340c9f439bd22b5e087eba9e
parent 25917 accb8d46284caa05b6a015db388d7e4c1423877b
child 25919 4b4f1518b7229296b44c563236183c6c2fe1e29e
push id1771
push userclokep@gmail.com
push dateMon, 14 Nov 2016 17:47:53 +0000
treeherdercomm-beta@399ae9d71595 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1301706
Bug 1301706 - Check return value of nsIURI::GetSpec. r=mkmelin
mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp
mailnews/base/src/nsMessenger.cpp
mailnews/base/src/nsMsgContentPolicy.cpp
mailnews/base/util/nsMsgMailNewsUrl.cpp
mailnews/compose/src/nsMsgAttachmentHandler.cpp
mailnews/compose/src/nsMsgCompUtils.cpp
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapProtocol.cpp
mailnews/imap/src/nsImapService.cpp
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsMailboxService.cpp
mailnews/local/src/nsMailboxUrl.cpp
mailnews/mime/src/mimedrft.cpp
mailnews/mime/src/mimemoz2.cpp
mailnews/news/src/nsNntpUrl.cpp
--- a/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp
@@ -358,21 +358,17 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::Do
     mCurrentMechanism = saslMechanism;
     mCurrentProtocolVersion = protocolVersion;
     redoConnection = true;
   }
   else
   {
     bool equal;
     rv = mDirectoryUrl->Equals(currentUrl, &equal);
-      NS_ENSURE_SUCCESS(rv, rv);
-  
-    nsCString spec;
-    mDirectoryUrl->GetSpec(spec);
-    currentUrl->GetSpec(spec);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     if (!equal)
     {
       mDirectoryUrl = currentUrl;
       aDirectory->GetUuid(mDirectoryId);
       mCurrentLogin = login;
       mCurrentMechanism = saslMechanism;
       mCurrentProtocolVersion = protocolVersion;
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -653,17 +653,18 @@ nsresult nsMessenger::SaveAttachment(nsI
   {
     saveListener->m_saveAllAttachmentsState = saveState;
     if (saveState->m_detachingAttachments)
     {
       nsCOMPtr<nsIURI> outputURI;
       nsresult rv = NS_NewFileURI(getter_AddRefs(outputURI), aFile);
       NS_ENSURE_SUCCESS(rv, rv);
       nsAutoCString fileUriSpec;
-      outputURI->GetSpec(fileUriSpec);
+      rv = outputURI->GetSpec(fileUriSpec);
+      NS_ENSURE_SUCCESS(rv, rv);
       saveState->m_savedFiles.AppendElement(fileUriSpec);
     }
   }
 
   urlString = aURL;
   // strip out ?type=application/x-message-display because it confuses libmime
 
   int32_t typeIndex = urlString.Find("?type=application/x-message-display");
--- a/mailnews/base/src/nsMsgContentPolicy.cpp
+++ b/mailnews/base/src/nsMsgContentPolicy.cpp
@@ -162,21 +162,19 @@ nsMsgContentPolicy::ShouldLoad(uint32_t 
   //
   // In most cases if an error occurs, its something we didn't expect so we
   // should be rejecting the document anyway.
   *aDecision = nsIContentPolicy::ACCEPT;
 
   NS_ENSURE_ARG_POINTER(aContentLocation);
 
 #ifdef DEBUG_MsgContentPolicy
-  nsCString spec;
-  (void)aContentLocation->GetSpec(spec);
   fprintf(stderr, "aContentType: %d\naContentLocation = %s\n",
           aContentType,
-          spec.get());
+          aContentLocation->GetSpecOrDefault().get());
 #endif
 
 #ifndef MOZ_THUNDERBIRD
   // Go find out if we are dealing with mailnews. Anything else
   // isn't our concern and we accept content.
   nsCOMPtr<nsIDocShell> rootDocShell;
   rv = GetRootDocShellForContext(aRequestingContext,
                                  getter_AddRefs(rootDocShell));
@@ -225,18 +223,17 @@ nsMsgContentPolicy::ShouldLoad(uint32_t 
 
   // NOTE: Not using NS_ENSURE_ARG_POINTER because this is a legitimate case
   // that can happen.  Also keep in mind that the default policy used for a
   // failure code is ACCEPT.
   if (!aRequestingLocation)
     return NS_ERROR_INVALID_POINTER;
 
 #ifdef DEBUG_MsgContentPolicy
-  (void)aRequestingLocation->GetSpec(spec);
-  fprintf(stderr, "aRequestingLocation = %s\n", spec.get());
+  fprintf(stderr, "aRequestingLocation = %s\n", aRequestingLocation->GetSpecOrDefault().get());
 #endif
 
   // If the requesting location is safe, accept the content location request.
   if (IsSafeRequestingLocation(aRequestingLocation))
     return rv;
 
   // Now default to reject so early returns via NS_ENSURE_SUCCESS
   // cause content to be rejected.
@@ -288,18 +285,17 @@ nsMsgContentPolicy::ShouldLoad(uint32_t 
   else
   {
     rv = GetOriginatingURIForContext(aRequestingContext,
                                      getter_AddRefs(originatorLocation));
   }
   NS_ENSURE_SUCCESS(rv, NS_OK);
 
 #ifdef DEBUG_MsgContentPolicy
-  (void)originatorLocation->GetSpec(spec);
-  fprintf(stderr, "originatorLocation = %s\n", spec.get());
+  fprintf(stderr, "originatorLocation = %s\n", originatorLocation->GetSpecOrDefault().get());
 #endif
 
   // Allow content when using a remote page.
   bool isHttp;
   bool isHttps;
   rv = originatorLocation->SchemeIs("http", &isHttp);
   nsresult rv2 = originatorLocation->SchemeIs("https", &isHttps);
   if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(rv2) && (isHttp || isHttps))
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -129,17 +129,18 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetServe
 
   nsresult rv;
   nsAutoCString urlstr;
   nsAutoCString scheme;
 
   nsCOMPtr<nsIURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
   if (NS_FAILED(rv)) return rv;
 
-  m_baseURL->GetSpec(urlstr);
+  rv = m_baseURL->GetSpec(urlstr);
+  NS_ENSURE_SUCCESS(rv, rv);
   rv = url->SetSpec(urlstr);
   if (NS_FAILED(rv)) return rv;
   rv = GetScheme(scheme);
     if (NS_SUCCEEDED(rv))
     {
         if (scheme.EqualsLiteral("pop"))
           scheme.Assign("pop3");
         // we use "nntp" in the server list so translate it here.
--- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp
+++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp
@@ -168,17 +168,20 @@ NS_IMETHODIMP nsMsgAttachmentHandler::Ge
 {
   nsAutoCString turl;
   if (!mURL)
   {
     if (!m_uri.IsEmpty())
       turl = m_uri;
   }
   else
-    mURL->GetSpec(turl);
+  {
+    nsresult rv = mURL->GetSpec(turl);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
   aUri.Assign(turl);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgAttachmentHandler::GetTmpFile(nsIFile **aTmpFile)
 {
   NS_ENSURE_ARG_POINTER(aTmpFile);
   if (!mTmpFile)
@@ -734,17 +737,18 @@ nsMsgAttachmentHandler::SnarfAttachment(
       }
     }
     mTmpFile->Remove(false);
     mTmpFile = nullptr;
     return NS_MSG_UNABLE_TO_OPEN_TMP_FILE;
   }
 
   nsCString sourceURISpec;
-  mURL->GetSpec(sourceURISpec);
+  rv = mURL->GetSpec(sourceURISpec);
+  NS_ENSURE_SUCCESS(rv, rv);
 #ifdef XP_MACOSX
   if (!m_bogus_attachment && StringBeginsWith(sourceURISpec, NS_LITERAL_CSTRING("file://")))
   {
     // Unescape the path (i.e. un-URLify it) before making a FSSpec
     nsAutoCString filePath;
     filePath.Adopt(nsMsgGetLocalFileFromURL(sourceURISpec.get()));
     nsAutoCString unescapedFilePath;
     MsgUnescapeString(filePath, 0, unescapedFilePath);
@@ -970,18 +974,18 @@ nsMsgAttachmentHandler::ConvertToAppleEn
 
     nsCOMPtr <nsIURI> fileURI;
     NS_NewFileURI(getter_AddRefs(fileURI), mEncodedWorkingFile);
 
     nsCOMPtr<nsIFileURL> theFileURL = do_QueryInterface(fileURI, &rv);
     NS_ENSURE_SUCCESS(rv,rv);
 
     nsCString newURLSpec;
+    rv = fileURI->GetSpec(newURLSpec);
     NS_ENSURE_SUCCESS(rv, rv);
-    fileURI->GetSpec(newURLSpec);
 
     if (newURLSpec.IsEmpty())
     {
       PR_FREEIF(separator);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     if (NS_FAILED(nsMsgNewURL(getter_AddRefs(mURL), newURLSpec.get())))
--- a/mailnews/compose/src/nsMsgCompUtils.cpp
+++ b/mailnews/compose/src/nsMsgCompUtils.cpp
@@ -1404,17 +1404,19 @@ msg_pick_real_name (nsMsgAttachmentHandl
 
   if (proposedName && *proposedName)
   {
     attachment->m_realName.Adopt(ToNewUTF8String(nsAutoString(proposedName)));
   }
   else //Let's extract the name from the URL
   {
     nsCString url;
-    attachment->mURL->GetSpec(url);
+    nsresult rv = attachment->mURL->GetSpec(url);
+    if (NS_FAILED(rv))
+      return;
 
     s = url.get();
     s2 = PL_strchr (s, ':');
     if (s2)
       s = s2 + 1;
     /* If we know the URL doesn't have a sensible file name in it,
      don't bother emitting a content-disposition. */
     if (StringBeginsWith (url, NS_LITERAL_CSTRING("news:"), nsCaseInsensitiveCStringComparator()) ||
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -432,17 +432,18 @@ nsresult nsMsgCompose::ResetUrisForEmbed
         rv = GetMessageServiceFromURI(newURI, getter_AddRefs(msgService));
         if (NS_FAILED(rv))
           continue;
         nsCOMPtr<nsIURI> newUrl;
         rv = msgService->GetUrlForUri(newURI.get(), getter_AddRefs(newUrl), nullptr);
         if (!newUrl)
           continue;
         nsCString spec;
-        newUrl->GetSpec(spec);
+        rv = newUrl->GetSpec(spec);
+        NS_ENSURE_SUCCESS(rv, rv);
         nsString newSrc;
         // mailbox urls will have ?number=xxx; imap urls won't. We need to
         // handle both cases because we may be going from a mailbox url to
         // and imap url, or vice versa, depending on the original folder,
         // and the destination drafts folder.
         bool specHasQ = (spec.FindChar('?') != kNotFound);
         if (specHasQ && restOfUrl.CharAt(0) == '?')
           restOfUrl.SetCharAt('&', 0);
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -1068,18 +1068,21 @@ nsMsgComposeAndSend::PreProcessPart(nsMs
     ma->m_encoding = ENCODING_7BIT;
 
   nsCString turl;
   if (!ma->mURL)
   {
     if (!ma->m_uri.IsEmpty())
       turl = ma->m_uri;
   }
-  else
-    ma->mURL->GetSpec(turl);
+  else {
+    status = ma->mURL->GetSpec(turl);
+    if (NS_FAILED(status))
+      return 0;
+  }
 
   nsCString type(ma->m_type);
   nsCString realName(ma->m_realName);
 
   // for cloud attachments, make the part an html part with no name,
   // so we don't show it as an attachment.
   if (ma->mSendViaCloud)
   {
@@ -1109,17 +1112,20 @@ nsMsgComposeAndSend::PreProcessPart(nsMs
   if (!hdrs)
     return 0;
 
   status = part->SetOtherHeaders(hdrs);
   PR_FREEIF(hdrs);
   if (ma->mSendViaCloud)
   {
     nsCString urlSpec;
-    ma->mURL->GetSpec(urlSpec);
+    status = ma->mURL->GetSpec(urlSpec);
+    if (NS_FAILED(status))
+      return 0;
+
     // Need to add some headers so that libmime can restore the cloud info
     // when loading a draft message.
     nsCString draftInfo(HEADER_X_MOZILLA_CLOUD_PART": cloudFile; url=");
     draftInfo.Append(ma->mCloudUrl.get());
     // don't leak user file paths or account keys to recipients.
     if (m_deliver_mode == nsMsgSaveAsDraft)
     {
       draftInfo.Append("; provider=");
@@ -1326,17 +1332,18 @@ nsMsgComposeAndSend::GetEmbeddedObjectIn
           return NS_ERROR_OUT_OF_MEMORY;
 
         nsAutoCString spec;
         nsIURI *uri = doc->GetDocumentURI();
 
         if (!uri)
           return NS_ERROR_OUT_OF_MEMORY;
 
-        uri->GetSpec(spec);
+        rv = uri->GetSpec(spec);
+        NS_ENSURE_SUCCESS(rv, rv);
 
         // Ok, now get the path to the root doc and tack on the name we
         // got from the GetSrc() call....
         NS_ConvertUTF8toUTF16 workURL(spec);
 
         int32_t loc = workURL.RFindChar('/');
         if (loc >= 0)
           workURL.SetLength(loc+1);
@@ -4162,17 +4169,19 @@ BuildURLAttachmentData(nsIURI *url)
     return nullptr;
 
   attachments = new nsMsgAttachmentData[attachCount];
   if (!attachments)
     return nullptr;
 
   // Now get a readable name...
   nsAutoCString spec;
-  url->GetSpec(spec);
+  nsresult rv = url->GetSpec(spec);
+  if (NS_FAILED(rv))
+    return nullptr;
   if (!spec.IsEmpty())
   {
     theName = strrchr(spec.get(), '/');
   }
 
   if (!theName)
     theName = "Unknown"; // Don't I18N this string...should never happen...
   else
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -5206,20 +5206,18 @@ nsImapMailFolder::OnStopRunningUrl(nsIUR
   }
     nsCOMPtr<nsIMsgWindow> msgWindow;
     nsCOMPtr<nsIMsgMailNewsUrl> mailUrl = do_QueryInterface(aUrl);
     bool folderOpen = false;
     if (mailUrl)
       mailUrl->GetMsgWindow(getter_AddRefs(msgWindow));
     if (session)
       session->IsFolderOpenInWindow(this, &folderOpen);
-#ifdef DEBUG_bienvenu1
-    nsCString urlSpec;
-    aUrl->GetSpec(getter_Copies(urlSpec));
-    printf("stop running url %s\n", urlSpec);
+#ifdef DEBUG_bienvenu
+    printf("stop running url %s\n", aUrl->GetSpecOrDefault().get());
 #endif
 
    if (imapUrl)
    {
       DisplayStatusMsg(imapUrl, EmptyString());
       imapUrl->GetImapAction(&imapAction);
       if (imapAction == nsIImapUrl::nsImapMsgFetch || imapAction == nsIImapUrl::nsImapMsgDownloadForOffline)
       {
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -1609,17 +1609,18 @@ bool nsImapProtocol::ProcessCurrentURL()
 
   // Reinitialize the parser
   GetServerStateParser().InitializeState();
   GetServerStateParser().SetConnected(true);
 
   // acknowledge that we are running the url now..
   nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningUrl, &rv);
   nsAutoCString urlSpec;
-  mailnewsurl->GetSpec(urlSpec);
+  rv = mailnewsurl->GetSpec(urlSpec);
+  NS_ENSURE_SUCCESS(rv, false);
   Log("ProcessCurrentURL", urlSpec.get(), (validUrl) ? " = currentUrl\n" : " is not valid\n");
   if (!validUrl)
     return false;
 
   if (NS_SUCCEEDED(rv) && mailnewsurl && m_imapMailFolderSink && !rerunningUrl)
     m_imapMailFolderSink->SetUrlState(this, mailnewsurl, true, false,
                                       NS_OK);
 
@@ -2122,19 +2123,17 @@ bool nsImapProtocol::TryToRunUrlLocally(
 // on this monitor). There is a contract that the imap thread has already been started b4 we
 // attempt to load a url....
 NS_IMETHODIMP nsImapProtocol::LoadImapUrl(nsIURI * aURL, nsISupports * aConsumer)
 {
   nsresult rv;
   if (aURL)
   {
 #ifdef DEBUG_bienvenu
-    nsAutoCString urlSpec;
-    aURL->GetSpec(urlSpec);
-    printf("loading url %s\n", urlSpec.get());
+    printf("loading url %s\n", aURL->GetSpecOrDefault().get());
 #endif
     if (TryToRunUrlLocally(aURL, aConsumer))
       return NS_OK;
     m_urlInProgress = true;
     m_imapMailFolderSink = nullptr;
     rv = SetupWithUrl(aURL, aConsumer);
     NS_ASSERTION(NS_SUCCEEDED(rv), "error setting up imap url");
     if (NS_FAILED(rv))
@@ -2625,17 +2624,17 @@ void nsImapProtocol::ProcessSelectedStat
               m_runningUrl->GetMimePartSelectorDetected(&mimePartSelectorDetected);
               m_runningUrl->GetFetchPartsOnDemand(&urlOKToFetchByParts);
 
 #ifdef PR_LOGGING
               {
                 nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningUrl);
                 nsAutoCString urlSpec;
                 if (mailnewsurl)
-                  mailnewsurl->GetSpec(urlSpec);
+                  urlSpec = mailnewsurl->GetSpecOrDefault();
                 MOZ_LOG(IMAP, LogLevel::Debug,
                        ("SHELL: URL %s, OKToFetchByParts %d, allowedToBreakApart %d, ShouldFetchAllParts %d",
                         urlSpec.get(), urlOKToFetchByParts, allowedToBreakApart,
                         GetShouldFetchAllParts()));
               }
 #endif
 
               if (urlOKToFetchByParts &&
@@ -4363,17 +4362,19 @@ bool nsImapProtocol::CheckNewMail()
     IMAP = PR_NewLogModule("IMAP");
 
   if (MOZ_LOG_TEST(IMAP, LogLevel::Info))
   {
     nsCOMPtr<nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(imapUrl);
     if (mailnewsUrl)
     {
       nsAutoCString urlSpec, unescapedUrlSpec;
-      mailnewsUrl->GetSpec(urlSpec);
+      nsresult rv = mailnewsUrl->GetSpec(urlSpec);
+      if (NS_FAILED(rv))
+        return;
       MsgUnescapeString(urlSpec, 0, unescapedUrlSpec);
       MOZ_LOG(IMAP, LogLevel::Info, ("%s:%s", logMsg, unescapedUrlSpec.get()));
     }
   }
 }
 
 // log info including current state...
 void nsImapProtocol::Log(const char *logSubName, const char *extraInfo, const char *logData)
--- a/mailnews/imap/src/nsImapService.cpp
+++ b/mailnews/imap/src/nsImapService.cpp
@@ -259,17 +259,18 @@ NS_IMETHODIMP nsImapService::GetUrlForUr
     rv = SetImapUrlSink(folder, imapUrl);
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr <nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(imapUrl);
     bool useLocalCache = false;
     folder->HasMsgOffline(atoi(msgKey.get()), &useLocalCache);
     mailnewsUrl->SetMsgIsInLocalCache(useLocalCache);
 
     nsCOMPtr<nsIURI> url = do_QueryInterface(imapUrl);
-    url->GetSpec(urlSpec);
+    rv = url->GetSpec(urlSpec);
+    NS_ENSURE_SUCCESS(rv, rv);
     urlSpec.Append("fetch>UID>");
     urlSpec.Append(hierarchyDelimiter);
 
     nsAutoCString folderName;
     GetFolderName(folder, folderName);
     urlSpec.Append(folderName);
     urlSpec.Append(">");
     urlSpec.Append(msgKey);
@@ -578,17 +579,18 @@ nsresult nsImapService::FetchMimePart(ns
     bool useLocalCache = false;
     aImapMailFolder->HasMsgOffline(atoi(nsCString(messageIdentifierList).get()), &useLocalCache);
     msgurl->SetMsgIsInLocalCache(useLocalCache);
   }
   rv = aImapUrl->SetImapMessageSink(aImapMessage);
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsIURI> url = do_QueryInterface(aImapUrl);
-    url->GetSpec(urlSpec);
+    rv = url->GetSpec(urlSpec);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     // rhp: If we are displaying this message for the purpose of printing, we
     // need to append the header=print option.
     //
     if (mPrintingOperation)
       urlSpec.Append("?header=print");
 
     rv = url->SetSpec(urlSpec);
@@ -938,17 +940,18 @@ NS_IMETHODIMP nsImapService::SaveMessage
 NS_IMETHODIMP nsImapService::AddImapFetchToUrl(nsIURI *aUrl,
                                                nsIMsgFolder *aImapMailFolder,
                                                const nsACString &aMessageIdentifierList,
                                                const nsACString &aAdditionalHeader)
 {
   NS_ENSURE_ARG_POINTER(aUrl);
 
   nsAutoCString urlSpec;
-  aUrl->GetSpec(urlSpec);
+  nsresult rv = aUrl->GetSpec(urlSpec);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   char hierarchyDelimiter = GetHierarchyDelimiter(aImapMailFolder);
 
   urlSpec.Append("fetch>UID>");
   urlSpec.Append(hierarchyDelimiter);
 
   nsAutoCString folderName;
   GetFolderName(aImapMailFolder, folderName);
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -3147,17 +3147,18 @@ nsresult nsMsgLocalMailFolder::CreateBas
 NS_IMETHODIMP
 nsMsgLocalMailFolder::OnStartRunningUrl(nsIURI * aUrl)
 {
   nsresult rv;
   nsCOMPtr<nsIPop3URL> popurl = do_QueryInterface(aUrl, &rv);
   if (NS_SUCCEEDED(rv))
   {
     nsAutoCString aSpec;
-    aUrl->GetSpec(aSpec);
+    rv = aUrl->GetSpec(aSpec);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (strstr(aSpec.get(), "uidl="))
     {
       nsCOMPtr<nsIPop3Sink> popsink;
       rv = popurl->GetPop3Sink(getter_AddRefs(popsink));
       if (NS_SUCCEEDED(rv))
       {
         popsink->SetBaseMessageUri(mBaseMessageURI.get());
         nsCString messageuri;
@@ -3184,18 +3185,20 @@ nsMsgLocalMailFolder::OnStopRunningUrl(n
   nsresult rv;
   if (NS_SUCCEEDED(aExitCode))
   {
     nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr<nsIMsgWindow> msgWindow;
     rv = mailSession->GetTopmostMsgWindow(getter_AddRefs(msgWindow));
     nsAutoCString aSpec;
-    if (aUrl)
-    aUrl->GetSpec(aSpec);
+    if (aUrl) {
+      rv = aUrl->GetSpec(aSpec);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
 
     if (strstr(aSpec.get(), "uidl="))
     {
       nsCOMPtr<nsIPop3URL> popurl = do_QueryInterface(aUrl, &rv);
       if (NS_SUCCEEDED(rv))
       {
         nsCString messageuri;
         rv = popurl->GetMessageUri(getter_Copies(messageuri));
--- a/mailnews/local/src/nsMailboxService.cpp
+++ b/mailnews/local/src/nsMailboxService.cpp
@@ -578,17 +578,18 @@ NS_IMETHODIMP nsMailboxService::NewChann
 NS_IMETHODIMP nsMailboxService::NewChannel2(nsIURI *aURI,
                                             nsILoadInfo *aLoadInfo,
                                             nsIChannel **_retval)
 {
   NS_ENSURE_ARG_POINTER(aURI);
   NS_ENSURE_ARG_POINTER(_retval);
   nsresult rv = NS_OK;
   nsAutoCString spec;
-  aURI->GetSpec(spec);
+  rv = aURI->GetSpec(spec);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (spec.Find("?uidl=") >= 0 || spec.Find("&uidl=") >= 0)
   {
     nsCOMPtr<nsIProtocolHandler> handler =
              do_GetService(NS_POP3SERVICE_CONTRACTID1, &rv);
     if (NS_SUCCEEDED(rv))
     {
       nsCOMPtr <nsIURI> pop3Uri;
--- a/mailnews/local/src/nsMailboxUrl.cpp
+++ b/mailnews/local/src/nsMailboxUrl.cpp
@@ -160,18 +160,20 @@ NS_IMETHODIMP nsMailboxUrl::GetUri(char 
       nsresult rv;
       nsCOMPtr<nsIMsgAccountManager> accountManager =
         do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
       NS_ENSURE_SUCCESS(rv, rv);
 
       // we blow off errors here so that we can open attachments
       // in .eml files.
       (void) accountManager->FolderUriForPath(m_filePath, baseUri);
-      if (baseUri.IsEmpty())
-        m_baseURL->GetSpec(baseUri);
+      if (baseUri.IsEmpty()) {
+        rv = m_baseURL->GetSpec(baseUri);
+        NS_ENSURE_SUCCESS(rv, rv);
+      }
       nsCString baseMessageURI;
       nsCreateLocalBaseMessageURI(baseUri, baseMessageURI);
       nsAutoCString uriStr;
       nsBuildLocalMessageURI(baseMessageURI.get(), m_messageKey, uriStr);
       *aURI = ToNewCString(uriStr);
     }
     else
       *aURI = nullptr;
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -138,19 +138,18 @@ mime_dump_attachments ( nsMsgAttachmentD
   class nsMsgAttachmentData  *tmp = attachData;
 
   while ( (tmp) && (tmp->m_url) )
   {
     printf("Real Name         : %s\n", tmp->m_realName.get());
 
     if ( tmp->m_url )
     {
-      nsAutoCString spec;
-      tmp->m_url->GetSpec(spec);
-      printf("URL               : %s\n", spec.get());
+      ;
+      printf("URL               : %s\n", tmp->m_url->GetSpecOrDefault().get());
     }
 
     printf("Desired Type      : %s\n", tmp->m_desiredType.get());
     printf("Real Type         : %s\n", tmp->m_realType.get());
     printf("Real Encoding     : %s\n", tmp->m_realEncoding.get());
     printf("Description       : %s\n", tmp->m_description.get());
     printf("Mac Type          : %s\n", tmp->m_xMacType.get());
     printf("Mac Creator       : %s\n", tmp->m_xMacCreator.get());
--- a/mailnews/mime/src/mimemoz2.cpp
+++ b/mailnews/mime/src/mimemoz2.cpp
@@ -673,18 +673,24 @@ NotifyEmittersOfAttachmentList(MimeDispl
         (opt->html_as_p != 4 || opt->metadata_only))))
     {
       ++i;
       ++tmp;
       continue;
     }
 
     nsAutoCString spec;
-    if (tmp->m_url)
-      tmp->m_url->GetSpec(spec);
+    if (tmp->m_url) {
+      nsresult rv = tmp->m_url->GetSpec(spec);
+      if (NS_FAILED(rv)) {
+        ++i;
+        ++tmp;
+        continue;
+      }
+    }
 
     nsAutoCString sizeStr;
     if (tmp->m_isExternalLinkAttachment)
       sizeStr.Append(tmp->m_sizeExternalStr);
     else
       sizeStr.AppendInt(tmp->m_size);
     nsAutoCString downloadedStr;
     downloadedStr.AppendInt(tmp->m_isDownloaded);
--- a/mailnews/news/src/nsNntpUrl.cpp
+++ b/mailnews/news/src/nsNntpUrl.cpp
@@ -102,17 +102,18 @@ NS_IMETHODIMP nsNntpUrl::SetSpec(const n
 
   if (scheme.EqualsLiteral("news") || scheme.EqualsLiteral("snews"))
     rv = ParseNewsURL();
   else if (scheme.EqualsLiteral("nntp") || scheme.EqualsLiteral("nntps"))
     rv = ParseNntpURL();
   else if (scheme.EqualsLiteral("news-message"))
   {
     nsAutoCString spec;
-    GetSpec(spec);
+    rv = GetSpec(spec);
+    NS_ENSURE_SUCCESS(rv, rv);
     rv = nsParseNewsMessageURI(spec.get(), m_group, &m_key);
     NS_ENSURE_SUCCESS(rv, NS_ERROR_MALFORMED_URI);
   }
   else
     return NS_ERROR_MALFORMED_URI;
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = DetermineNewsAction();
@@ -133,17 +134,18 @@ nsresult nsNntpUrl::ParseNewsURL()
 
   // The presence of an `@' is a sign we have a msgid
   if (path.Find("@") != -1 || path.Find("%40") != -1)
   {
     MsgUnescapeString(path, 0, m_messageID);
 
     // Set group, key for ?group=foo&key=123 uris
     nsAutoCString spec;
-    GetSpec(spec);
+    rv = GetSpec(spec);
+    NS_ENSURE_SUCCESS(rv, rv);
     int32_t groupPos = spec.Find(kNewsURIGroupQuery); // find ?group=
     int32_t keyPos   = spec.Find(kNewsURIKeyQuery);   // find &key=
     if (groupPos != kNotFound && keyPos != kNotFound)
     {
       // get group name and message key
       m_group = Substring(spec, groupPos + kNewsURIGroupQueryLen,
                           keyPos - groupPos - kNewsURIGroupQueryLen);
       nsCString keyStr(Substring(spec, keyPos + kNewsURIKeyQueryLen));
@@ -372,21 +374,23 @@ NS_IMETHODIMP nsNntpUrl::GetMessageHeade
 
   nsCOMPtr <nsINntpService> nntpService = do_GetService(NS_NNTPSERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsCOMPtr <nsIMsgMessageService> msgService = do_QueryInterface(nntpService, &rv);
   NS_ENSURE_SUCCESS(rv,rv);
 
   nsAutoCString spec(mOriginalSpec);
-  if (spec.IsEmpty())
+  if (spec.IsEmpty()) {
     // Handle the case where necko directly runs an internal news:// URL,
     // one that looks like news://host/message-id?group=mozilla.announce&key=15
     // Other sorts of URLs -- e.g. news://host/message-id -- will not succeed.
-    GetSpec(spec);
+    rv = GetSpec(spec);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   return msgService->MessageURIToMsgHdr(spec.get(), aMsgHdr);
 }
 
 NS_IMETHODIMP nsNntpUrl::IsUrlType(uint32_t type, bool *isType)
 {
   NS_ENSURE_ARG(isType);