Bug 1257058 - Distinguish 'empty password' from no password received to avoid shutdown crash. r=mkmelin a=jorgk
authorJorg K <jorgk@jorgk.com>
Mon, 05 Nov 2018 21:44:28 +0100
changeset 33474 f9d7095faf28964f57252e818c13f725b15a9bee
parent 33473 d8eadcb6eb3207b5b03aa89e6adb3ea2a447b8f3
child 33475 d8c8c5433d0cf0859216391f96be398654049b1b
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersmkmelin, jorgk
bugs1257058
Bug 1257058 - Distinguish 'empty password' from no password received to avoid shutdown crash. r=mkmelin a=jorgk
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;