Bug 1563959 - Check that we got a non-null header before running a filter on it (and crashing). r=aceman a=jorgk BETA_68_CONTINUATION
authorJorg K <jorgk@jorgk.com>
Mon, 08 Jul 2019 00:21:10 +0200
branchBETA_68_CONTINUATION
changeset 36062 f53a5e4487e6a27251cd7d45937edef39d05129e
parent 36061 be43f86e0509f04130b512f61ddbbe2777d2bcb2
child 36063 883281c5e30fc82ae8b787187f0c220ac7e66cf0
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersaceman, jorgk
bugs1563959
Bug 1563959 - Check that we got a non-null header before running a filter on it (and crashing). r=aceman a=jorgk
mailnews/base/search/src/nsMsgFilterList.cpp
--- a/mailnews/base/search/src/nsMsgFilterList.cpp
+++ b/mailnews/base/search/src/nsMsgFilterList.cpp
@@ -270,16 +270,24 @@ NS_IMETHODIMP
 nsMsgFilterList::ApplyFiltersToHdr(nsMsgFilterTypeType filterType,
                                    nsIMsgDBHdr *msgHdr, nsIMsgFolder *folder,
                                    nsIMsgDatabase *db,
                                    const nsACString &headers,
                                    nsIMsgFilterHitNotify *listener,
                                    nsIMsgWindow *msgWindow) {
   MOZ_LOG(FILTERLOGMODULE, LogLevel::Debug,
           ("(Auto) nsMsgFilterList::ApplyFiltersToHdr"));
+  if (!msgHdr) {
+    // Sometimes we get here with no header, so let's not crash on that
+    // later on.
+    MOZ_LOG(FILTERLOGMODULE, LogLevel::Debug,
+            ("(Auto) Called with NULL message header, nothing to do"));
+    return NS_ERROR_NULL_POINTER;
+  }
+
   nsCOMPtr<nsIMsgFilter> filter;
   uint32_t filterCount = 0;
   nsresult rv = GetFilterCount(&filterCount);
   NS_ENSURE_SUCCESS(rv, rv);
 
   RefPtr<nsMsgSearchScopeTerm> scope =
       new nsMsgSearchScopeTerm(nullptr, nsMsgSearchScope::offlineMail, folder);
 
@@ -319,17 +327,17 @@ nsMsgFilterList::ApplyFiltersToHdr(nsMsg
       if (curFilterType & filterType) {
         MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
                 ("(Auto) Running filter %" PRIu32, filterIndex));
         MOZ_LOG(FILTERLOGMODULE, LogLevel::Debug,
                 ("(Auto) Filter name: %s",
                  NS_ConvertUTF16toUTF8(filterName).get()));
 
         nsresult matchTermStatus = NS_OK;
-        bool result;
+        bool result = false;
 
         filter->SetScope(scope);
         matchTermStatus =
             filter->MatchHdr(msgHdr, folder, db, headers, &result);
         filter->SetScope(nullptr);
         if (NS_SUCCEEDED(matchTermStatus) && result && listener) {
           nsCString msgId;
           msgHdr->GetMessageId(getter_Copies(msgId));