Bug 825513 - Fix crash in nsImapProtocol::GetMessageSize() by adding null check for m_runningUrl && m_hostSessionList. r+a=jorgk
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Sat, 06 Oct 2018 21:38:58 +0200
changeset 33048 872d9710ea55
parent 33047 65ed6e7ef6d9
child 33049 90c267d6d48f
push id386
push userclokep@gmail.com
push dateTue, 23 Oct 2018 00:48:12 +0000
bugs825513
Bug 825513 - Fix crash in nsImapProtocol::GetMessageSize() by adding null check for m_runningUrl && m_hostSessionList. r+a=jorgk
mailnews/imap/src/nsImapProtocol.cpp
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -4553,56 +4553,45 @@ 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)
+uint32_t nsImapProtocol::GetMessageSize(const char * messageId, bool idsAreUids)
 {
   const char *folderFromParser = GetServerStateParser().GetSelectedMailboxName();
-  if (folderFromParser && messageId)
-  {
-    char *id = (char *)PR_CALLOC(strlen(messageId) + 1);
-    char *folderName;
-    uint32_t size;
-
-    PL_strcpy(id, messageId);
-
-    nsIMAPNamespace *nsForMailbox = nullptr;
-        m_hostSessionList->GetNamespaceForMailboxForHost(GetImapServerKey(), folderFromParser,
-            nsForMailbox);
-
-
-    if (nsForMailbox)
-          m_runningUrl->AllocateCanonicalPath(
-              folderFromParser, nsForMailbox->GetDelimiter(),
-              &folderName);
-    else
-       m_runningUrl->AllocateCanonicalPath(
-          folderFromParser,kOnlineHierarchySeparatorUnknown,
-          &folderName);
-
-    if (id && folderName)
-    {
-      if (m_imapMessageSink)
-          m_imapMessageSink->GetMessageSizeFromDB(id, &size);
-    }
-    PR_FREEIF(id);
-    PR_FREEIF(folderName);
-
-    uint32_t rv = 0;
-    if (!DeathSignalReceived())
-      rv = size;
-    return rv;
-  }
-  return 0;
+  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);
+
+  if (DeathSignalReceived())
+    size = 0;
+
+  return size;
 }
 
 // message id string utility functions
 /* static */bool nsImapProtocol::HandlingMultipleMessages(const nsCString & messageIdString)
 {
   return (MsgFindCharInSet(messageIdString, ",:") != kNotFound);
 }