Bug 1609690 - Fix address-parsing crash on some IMAP servers when mail.imap.use_envelope_cmd is set. r=mkmelin DONTBUILD
authorBen Campbell <benc@thunderbird.net>
Mon, 20 Jan 2020 12:40:04 +0200
changeset 37102 c3804bf34462609beabc273724c4024408cc83e7
parent 37101 aa09b869e1e5ac06a4a8d70e72d3d2d54fd4b44b
child 37103 e0752dc7296ce078822f829194db329575baedb6
push id2552
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:24:16 +0000
treeherdercomm-beta@f95a6f4408a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1609690
Bug 1609690 - Fix address-parsing crash on some IMAP servers when mail.imap.use_envelope_cmd is set. r=mkmelin DONTBUILD
mailnews/imap/src/nsImapServerResponseParser.cpp
--- a/mailnews/imap/src/nsImapServerResponseParser.cpp
+++ b/mailnews/imap/src/nsImapServerResponseParser.cpp
@@ -1379,16 +1379,18 @@ void nsImapServerResponseParser::xaolenv
         }
         if (ContinueParse()) AdvanceToNextToken();  // skip )
       }
     }
   }
 }
 
 void nsImapServerResponseParser::parse_address(nsAutoCString &addressLine) {
+  // NOTE: Not sure this function correctly handling group address syntax.
+  // See Bug 1609846.
   if (!strcmp(fNextToken, "NIL")) return;
   bool firstAddress = true;
   // should really look at chars here
   NS_ASSERTION(*fNextToken == '(', "address should start with '('");
   fNextToken++;  // eat the next '('
   while (ContinueParse() && *fNextToken == '(') {
     NS_ASSERTION(*fNextToken == '(', "address should start with '('");
     fNextToken++;  // eat the next '('
@@ -1401,28 +1403,31 @@ void nsImapServerResponseParser::parse_a
     char *atDomainList = CreateNilString();
     if (ContinueParse()) {
       AdvanceToNextToken();
       char *mailboxName = CreateNilString();
       if (ContinueParse()) {
         AdvanceToNextToken();
         char *hostName = CreateNilString();
         AdvanceToNextToken();
-        addressLine += mailboxName;
+        if (mailboxName) {
+          addressLine += mailboxName;
+        }
         if (hostName) {
           addressLine += '@';
           addressLine += hostName;
-          free(hostName);
+          PR_Free(hostName);
         }
         if (personalName) {
           addressLine += " (";
           addressLine += personalName;
           addressLine += ')';
         }
       }
+      PR_Free(mailboxName);
     }
     PR_Free(personalName);
     PR_Free(atDomainList);
 
     if (*fNextToken == ')') fNextToken++;
     // if the next token isn't a ')' for the address term,
     // then we must have another address pair left....so get the next
     // token and continue parsing in this loop...