Bug 1280662 - Fix uninitialised var in nsImapProtocol::GetMessageSize(). r=mkmelin DONTBUILD
authorBen Campbell <benc@thunderbird.net>
Fri, 20 Mar 2020 12:59:23 +0200
changeset 38540 3528b15b3c008d410a37abdb2c363fc85954a051
parent 38539 ba0be99cb7702128a827d597aa80f4ea33deaccc
child 38541 d51e4a31fe1d03d1ce4c068b522aed0376174e7a
push id400
push userclokep@gmail.com
push dateMon, 04 May 2020 18:56:09 +0000
reviewersmkmelin
bugs1280662
Bug 1280662 - Fix uninitialised var in nsImapProtocol::GetMessageSize(). r=mkmelin DONTBUILD
mailnews/imap/src/nsIMAPBodyShell.cpp
mailnews/imap/src/nsImapProtocol.cpp
mailnews/imap/src/nsImapProtocol.h
--- a/mailnews/imap/src/nsIMAPBodyShell.cpp
+++ b/mailnews/imap/src/nsIMAPBodyShell.cpp
@@ -176,18 +176,17 @@ int32_t nsIMAPBodyShell::Generate(char *
 
   if (!GetIsValid() || PreflightCheckAllInline()) {
     // We don't have a valid shell, or all parts are going to be inline anyway.
     // Fall back to fetching the whole message.
 #ifdef DEBUG_chrisf
     NS_ASSERTION(GetIsValid());
 #endif
     m_generatingWholeMessage = true;
-    uint32_t messageSize =
-        m_protocolConnection->GetMessageSize(GetUID().get(), true);
+    uint32_t messageSize = m_protocolConnection->GetMessageSize(GetUID());
     MOZ_LOG(IMAPCache, LogLevel::Debug,
             ("Generate(): Set IMAP_CONTENT_NOT MODIFIED"));
     m_protocolConnection->SetContentModified(
         IMAP_CONTENT_NOT_MODIFIED);  // So that when we cache it, we know we
                                      // have the whole message
     if (!DeathSignalReceived())
       m_protocolConnection->FallbackToFetchWholeMsg(GetUID(), messageSize);
     contentLength = (int32_t)messageSize;  // ugh
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -2662,18 +2662,17 @@ void nsImapProtocol::ProcessSelectedStat
               } else {
                 // Message IDs are not UIDs.
                 NS_ASSERTION(false, "message ids aren't uids");
               }
               PR_Free(imappart);
             } else {
               // downloading a single message: try to do it by bodystructure,
               // and/or do it by chunks
-              uint32_t messageSize =
-                  GetMessageSize(messageIdString.get(), bMessageIdsAreUids);
+              uint32_t messageSize = GetMessageSize(messageIdString);
               // We need to check the format_out bits to see if we are allowed
               // to leave out parts, or if we are required to get the whole
               // thing.  Some instances where we are allowed to do it by parts:
               // when viewing a message, replying to a message, or viewing its
               // source Some times when we're NOT allowed:  when forwarding a
               // message, saving it, moving it, etc. need to set a flag in the
               // url, I guess, equiv to allow_content_changed.
               bool allowedToBreakApart =
@@ -4540,43 +4539,22 @@ void nsImapProtocol::Log(const char *log
       MOZ_LOG(IMAP, LogLevel::Info, ("%.400s", logDataToLog));
     }
   }
 }
 
 // In 4.5, this posted an event back to libmsg and blocked until it got a
 // response. We may still have to do this.It would be nice if we could preflight
 // this value, but we may not always know when we'll need it.
-uint32_t nsImapProtocol::GetMessageSize(const char *messageId,
-                                        bool idsAreUids) {
-  const char *folderFromParser =
-      GetServerStateParser().GetSelectedMailboxName();
-  if (!folderFromParser || !messageId || !m_runningUrl || !m_hostSessionList)
-    return 0;
-
-  char *folderName = nullptr;
-  uint32_t size;
-
-  nsIMAPNamespace *nsForMailbox = nullptr;
-  m_hostSessionList->GetNamespaceForMailboxForHost(
-      GetImapServerKey(), folderFromParser, nsForMailbox);
-
-  m_runningUrl->AllocateCanonicalPath(folderFromParser,
-                                      nsForMailbox
-                                          ? nsForMailbox->GetDelimiter()
-                                          : kOnlineHierarchySeparatorUnknown,
-                                      &folderName);
-
-  if (folderName && m_imapMessageSink)
-    m_imapMessageSink->GetMessageSizeFromDB(messageId, &size);
-
-  PR_FREEIF(folderName);
-
+uint32_t nsImapProtocol::GetMessageSize(const nsACString &messageId) {
+  uint32_t size = 0;
+  if (m_imapMessageSink)
+    m_imapMessageSink->GetMessageSizeFromDB(PromiseFlatCString(messageId).get(),
+                                            &size);
   if (DeathSignalReceived()) size = 0;
-
   return size;
 }
 
 // message id string utility functions
 /* static */ bool nsImapProtocol::HandlingMultipleMessages(
     const nsCString &messageIdString) {
   return (MsgFindCharInSet(messageIdString, ",:") != kNotFound);
 }
--- a/mailnews/imap/src/nsImapProtocol.h
+++ b/mailnews/imap/src/nsImapProtocol.h
@@ -254,17 +254,17 @@ class nsImapProtocol : public nsIImapPro
   // Send log output...
   void Log(const char *logSubName, const char *extraInfo, const char *logData);
   static void LogImapUrl(const char *logMsg, nsIImapUrl *imapUrl);
   // Comment from 4.5: We really need to break out the thread synchronizer from
   // the connection class...Not sure what this means
   bool GetPseudoInterrupted();
   void PseudoInterrupt(bool the_interrupt);
 
-  uint32_t GetMessageSize(const char *messageId, bool idsAreUids);
+  uint32_t GetMessageSize(const nsACString &messageId);
   bool GetSubscribingNow();
 
   bool DeathSignalReceived();
   void ResetProgressInfo();
   void SetActive(bool active);
   bool GetActive();
 
   bool GetShowAttachmentsInline();