Bug 1563959 - Check that we got a non-null header before running a filter on it (and crashing). r=aceman
authorJorg K <jorgk@jorgk.com>
Mon, 08 Jul 2019 00:21:10 +0200
changeset 36044 604b7c9f720c2c77cd0d5dff783e6e4049d9bd5e
parent 36043 af98d8b8999d534e1f460789c8c867cec3978ca0
child 36045 1ba917da139c6e707d6d964c5d1de142cab1e666
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersaceman
bugs1563959
Bug 1563959 - Check that we got a non-null header before running a filter on it (and crashing). r=aceman
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));