Bug 1257058 - Distinguish 'empty password' from no password received to avoid shutdown crash. r=mkmelin
authorJorg K <jorgk@jorgk.com>
Mon, 05 Nov 2018 21:44:28 +0100
changeset 32808 9f8543c1794e18fd07cac56dd5cc3aa99a89494e
parent 32807 7fcefde4be7f06455cd859fff3180c767cd8d1d2
child 32809 25adff603af0c4b0817fb34baa80185a76081704
push id2343
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:37:21 +0000
treeherdercomm-beta@a0750c375f71 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1257058
Bug 1257058 - Distinguish 'empty password' from no password received to avoid shutdown crash. r=mkmelin
mailnews/imap/src/nsImapProtocol.cpp
mailnews/imap/src/nsImapProtocol.h
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -8538,25 +8538,25 @@ nsresult nsImapProtocol::GetPassword(nsS
   rv = m_imapServerSink->GetServerPassword(password);
   if (NS_FAILED(rv) || password.IsEmpty())
   {
     AutoProxyReleaseMsgWindow msgWindow;
     GetMsgWindow(getter_AddRefs(msgWindow));
     NS_ENSURE_TRUE(msgWindow, NS_ERROR_NOT_AVAILABLE); // biff case
 
     // Get the password from pw manager (harddisk) or user (dialog)
-    nsAutoString pwd; // GetPasswordWithUI truncates the password on Cancel
+    m_passwordObtained = false;
     rv = m_imapServerSink->AsyncGetPassword(this, newPasswordRequested,
                                             password);
     if (password.IsEmpty())
     {
       PRIntervalTime sleepTime = kImapSleepTime;
       m_passwordStatus = NS_OK;
       ReentrantMonitorAutoEnter mon(m_passwordReadyMonitor);
-      while (m_password.IsEmpty() && !NS_FAILED(m_passwordStatus) &&
+      while (!m_passwordObtained && !NS_FAILED(m_passwordStatus) &&
              m_passwordStatus != NS_MSG_PASSWORD_PROMPT_CANCELLED &&
              !DeathSignalReceived())
         mon.Wait(sleepTime);
       rv = m_passwordStatus;
       password = m_password;
     }
   }
   if (!password.IsEmpty())
@@ -8585,29 +8585,31 @@ nsImapProtocol::OnPromptStart(bool *aRes
   nsString password = m_lastPasswordSent;
   rv = imapServer->PromptPassword(msgWindow, password);
   m_password = password;
   m_passwordStatus = rv;
   if (!m_password.IsEmpty())
     *aResult = true;
 
   // Notify the imap thread that we have a password.
+  m_passwordObtained = true;
   ReentrantMonitorAutoEnter passwordMon(m_passwordReadyMonitor);
   passwordMon.Notify();
   return rv;
 }
 
 NS_IMETHODIMP
 nsImapProtocol::OnPromptAuthAvailable()
 {
   nsresult rv;
   nsCOMPtr<nsIMsgIncomingServer> imapServer = do_QueryReferent(m_server, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   m_passwordStatus = imapServer->GetPassword(m_password);
   // Notify the imap thread that we have a password.
+  m_passwordObtained = true;
   ReentrantMonitorAutoEnter passwordMon(m_passwordReadyMonitor);
   passwordMon.Notify();
   return m_passwordStatus;
 }
 
 NS_IMETHODIMP
 nsImapProtocol::OnPromptCanceled()
 {
--- a/mailnews/imap/src/nsImapProtocol.h
+++ b/mailnews/imap/src/nsImapProtocol.h
@@ -376,16 +376,17 @@ private:
   mozilla::ReentrantMonitor m_passwordReadyMonitor;
   mozilla::Mutex mLock;
   // If we get an async password prompt, this is where the UI thread
   // stores the password, before notifying the imap thread of the password
   // via the m_passwordReadyMonitor.
   nsString m_password;
   // Set to the result of nsImapServer::PromptPassword
   nsresult    m_passwordStatus;
+  bool        m_passwordObtained;
 
   bool         m_imapThreadIsRunning;
   void ImapThreadMainLoop(void);
   nsresult    m_connectionStatus;
   nsCString   m_connectionType;
 
   bool        m_nextUrlReadyToRun;
   nsWeakPtr   m_server;