Bug 1668926 - Fix uninitialised pointer in nsMsgBodyHander. r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Fri, 26 Nov 2021 20:11:10 +0200
changeset 34406 0295d55c1fdea60192d6518ec9fe23a8664f1966
parent 34405 8c44f53caece8bfd13295337d23deba36dbc92ca
child 34407 1de142e49940402f5f2ca5c9105ba8a4b0199cdc
push id19412
push usermkmelin@iki.fi
push dateFri, 26 Nov 2021 18:11:36 +0000
treeherdercomm-central@0295d55c1fde [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1668926, 1137650
Bug 1668926 - Fix uninitialised pointer in nsMsgBodyHander. r=mkmelin CID 1137650 Uninitialized pointer field The pointer field will point to an arbitrary memory location, any attempt to write may cause corruption. In nsMsgBodyHandler::nsMsgBodyHandler(nsIMsgSearchScopeTerm *, unsigned int, nsIMsgDBHdr *, nsIMsgDatabase *, char const*, unsigned int, bool): A pointer field is not initialized in the constructor Differential Revision: https://phabricator.services.mozilla.com/D132209
mailnews/search/src/nsMsgBodyHandler.cpp
--- a/mailnews/search/src/nsMsgBodyHandler.cpp
+++ b/mailnews/search/src/nsMsgBodyHandler.cpp
@@ -29,17 +29,17 @@ nsMsgBodyHandler::nsMsgBodyHandler(nsIMs
   // account for added x-mozilla-status lines, and envelope line.
   if (!m_lineCountInBodyLines) m_numLocalLines += 3;
   m_msgHdr = msg;
   m_db = db;
 
   // the following are variables used when the body handler is handling stuff
   // from filters....through this constructor, that is not the case so we set
   // them to NULL.
-  m_headers = NULL;
+  m_headers = nullptr;
   m_headersSize = 0;
   m_Filtering = false;  // make sure we set this before we call initialize...
 
   Initialize();  // common initialization stuff
   OpenLocalFolder();
 }
 
 nsMsgBodyHandler::nsMsgBodyHandler(nsIMsgSearchScopeTerm* scope,
@@ -51,26 +51,28 @@ nsMsgBodyHandler::nsMsgBodyHandler(nsIMs
   uint32_t flags;
   m_lineCountInBodyLines = NS_SUCCEEDED(msg->GetFlags(&flags))
                                ? !(flags & nsMsgMessageFlags::Offline)
                                : true;
   // account for added x-mozilla-status lines, and envelope line.
   if (!m_lineCountInBodyLines) m_numLocalLines += 3;
   m_msgHdr = msg;
   m_db = db;
-  m_headersSize = headersSize;
+  m_headers = nullptr;
+  m_headersSize = 0;
   m_Filtering = Filtering;
 
   Initialize();
 
-  if (m_Filtering)
+  if (m_Filtering) {
     m_headers = headers;
-  else
-    OpenLocalFolder();  // if nothing else applies, then we must be a POP folder
-                        // file
+    m_headersSize = headersSize;
+  } else {
+    OpenLocalFolder();
+  }
 }
 
 void nsMsgBodyHandler::Initialize()
 // common initialization code regardless of what body type we are handling...
 {
   // Default transformations for local message search and MAPI access
   m_stripHeaders = true;
   m_partIsHtml = false;
@@ -89,19 +91,19 @@ nsMsgBodyHandler::~nsMsgBodyHandler() {}
 int32_t nsMsgBodyHandler::GetNextLine(nsCString& buf, nsCString& charset) {
   int32_t length = -1;     // length of incoming line or -1 eof
   int32_t outLength = -1;  // length of outgoing line or -1 eof
   bool eatThisLine = true;
   nsAutoCString nextLine;
 
   while (eatThisLine) {
     // first, handle the filtering case...this is easy....
-    if (m_Filtering)
+    if (m_Filtering) {
       length = GetNextFilterLine(nextLine);
-    else {
+    } else {
       // 3 cases: Offline IMAP, POP, or we are dealing with a news message....
       // Offline cases should be same as local mail cases, since we're going
       // to store offline messages in berkeley format folders.
       if (m_db) {
         length = GetNextLocalLine(nextLine);  // (2) POP
       }
     }