Bug 906469 - fix maildir crash while parsing a folder. r=jorgk
authorR Kent James <kent@caspia.com>
Sun, 16 Dec 2018 13:28:00 +0100
changeset 34015 e756111cbbd0804522a8cb5fffabcb48d5a61f38
parent 34014 f245d6f5d3b32a5ca10a7871eb4d1231550af3fc
child 34016 714714d80d62fdfee3fdab44314aeb7ac8614c01
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersjorgk
bugs906469
Bug 906469 - fix maildir crash while parsing a folder. r=jorgk
mailnews/local/src/nsMsgMaildirStore.cpp
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -1184,16 +1184,17 @@ MaildirStoreParser::MaildirStoreParser(n
 
 MaildirStoreParser::~MaildirStoreParser()
 {
 }
 
 nsresult MaildirStoreParser::ParseNextMessage(nsIFile *aFile)
 {
   nsresult rv;
+  NS_ENSURE_TRUE(m_db, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIInputStream> inputStream;
   nsCOMPtr<nsIMsgParseMailMsgState> msgParser =
     do_CreateInstance(NS_PARSEMAILMSGSTATE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   msgParser->SetMailDB(m_db);
   nsCOMPtr<nsIMsgDBHdr> newMsgHdr;
   rv = m_db->CreateNewHdr(nsMsgKey_None, getter_AddRefs(newMsgHdr));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -1266,19 +1267,20 @@ void MaildirStoreParser::TimerCallback(n
       }
     }
     // Parsing complete and timer cancelled, so we release the parser object.
     delete parser;
     return;
   }
   nsCOMPtr<nsIFile> currentFile;
   nsresult rv = parser->m_directoryEnumerator->GetNextFile(getter_AddRefs(currentFile));
-  NS_ENSURE_SUCCESS_VOID(rv);
-  parser->ParseNextMessage(currentFile);
-  // ### TODO - what if this fails?
+  if (NS_SUCCEEDED(rv))
+    rv = parser->ParseNextMessage(currentFile);
+  if (NS_FAILED(rv) && parser->m_listener)
+    parser->m_listener->OnStopRunningUrl(nullptr, NS_ERROR_FAILURE);
 }
 
 nsresult MaildirStoreParser::StartTimer()
 {
   nsresult rv;
   m_timer = do_CreateInstance("@mozilla.org/timer;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   m_timer->InitWithNamedFuncCallback(TimerCallback, (void *) this, 0,