Bug 145113 - Make "next chunk starts with newline" flag a member variable to fix MOZ_ASSERT().

Tag #1273
This commit is contained in:
Matt A. Tobin 2019-11-10 21:18:30 -05:00 • committed by Roy Tam
commit 791626aab1
2 changed files with 12 additions and 9 deletions

View file

@ -36,6 +36,7 @@ nsImapServerResponseParser::nsImapServerResponseParser(nsImapProtocol &imapProto
fSelectedMailboxName(nullptr), fSelectedMailboxName(nullptr),
fIMAPstate(kNonAuthenticated), fIMAPstate(kNonAuthenticated),
fLastChunk(false), fLastChunk(false),
fNextChunkStartsWithNewline(false),
fServerConnection(imapProtocolConnection), fServerConnection(imapProtocolConnection),
fHostSessionList(nullptr) fHostSessionList(nullptr)
{ {
@ -3110,7 +3111,6 @@ bool nsImapServerResponseParser::msg_fetch_literal(bool chunk, int32_t origin)
#endif #endif
charsReadSoFar = 0; charsReadSoFar = 0;
static bool nextChunkStartsWithNewline = false;
while (ContinueParse() && !fServerConnection.DeathSignalReceived() && (charsReadSoFar < numberOfCharsInThisChunk)) while (ContinueParse() && !fServerConnection.DeathSignalReceived() && (charsReadSoFar < numberOfCharsInThisChunk))
{ {
@ -3125,7 +3125,7 @@ bool nsImapServerResponseParser::msg_fetch_literal(bool chunk, int32_t origin)
// '\r' is not inserted so the beginning line of the next chunk remains // '\r' is not inserted so the beginning line of the next chunk remains
// just '\n' and no discard is required. // just '\n' and no discard is required.
// In any case, this "orphan" line is ignored and not processed below. // In any case, this "orphan" line is ignored and not processed below.
if (nextChunkStartsWithNewline && (*fCurrentLine == '\r')) if (fNextChunkStartsWithNewline && (*fCurrentLine == '\r'))
{ {
// Cause fCurrentLine to point to '\n' which discards the '\r'. // Cause fCurrentLine to point to '\n' which discards the '\r'.
char *usableCurrentLine = PL_strdup(fCurrentLine + 1); char *usableCurrentLine = PL_strdup(fCurrentLine + 1);
@ -3190,11 +3190,11 @@ bool nsImapServerResponseParser::msg_fetch_literal(bool chunk, int32_t origin)
(fCurrentLine + strlen(fCurrentLine) - (charsReadSoFar - numberOfCharsInThisChunk + 1)); (fCurrentLine + strlen(fCurrentLine) - (charsReadSoFar - numberOfCharsInThisChunk + 1));
// Save so original unmodified fCurrentLine is restored below. // Save so original unmodified fCurrentLine is restored below.
char saveit1 = displayEndOfLine[1]; char saveit1 = displayEndOfLine[1];
char saveit2; char saveit2 = 0; // Keep compiler happy.
// Determine if EOL is split such that Chunk X has the \r and chunk // Determine if EOL is split such that Chunk X has the \r and chunk
// X+1 has the \n. // X+1 has the \n.
nextChunkStartsWithNewline = (displayEndOfLine[0] == '\r'); fNextChunkStartsWithNewline = (displayEndOfLine[0] == '\r');
if (nextChunkStartsWithNewline) if (fNextChunkStartsWithNewline)
{ {
saveit2 = displayEndOfLine[2]; saveit2 = displayEndOfLine[2];
// Add the missing newline and terminate the string. // Add the missing newline and terminate the string.
@ -3212,13 +3212,13 @@ bool nsImapServerResponseParser::msg_fetch_literal(bool chunk, int32_t origin)
fServerConnection.HandleMessageDownLoadLine(fCurrentLine, !lastChunk); fServerConnection.HandleMessageDownLoadLine(fCurrentLine, !lastChunk);
// Restore fCurrentLine's original content. // Restore fCurrentLine's original content.
displayEndOfLine[1] = saveit1; displayEndOfLine[1] = saveit1;
if (nextChunkStartsWithNewline) if (fNextChunkStartsWithNewline)
displayEndOfLine[2] = saveit2; displayEndOfLine[2] = saveit2;
} }
else else
{ {
// Not the last line of a chunk. // Not the last line of a chunk.
if (!nextChunkStartsWithNewline) if (!fNextChunkStartsWithNewline)
{ {
// Process unmodified fCurrentLine string. // Process unmodified fCurrentLine string.
fServerConnection.HandleMessageDownLoadLine(fCurrentLine, fServerConnection.HandleMessageDownLoadLine(fCurrentLine,
@ -3230,7 +3230,7 @@ bool nsImapServerResponseParser::msg_fetch_literal(bool chunk, int32_t origin)
// Ignore the orphan '\n' on a line by itself. // Ignore the orphan '\n' on a line by itself.
MOZ_ASSERT(strlen(fCurrentLine) == 1 && fCurrentLine[0] == '\n', MOZ_ASSERT(strlen(fCurrentLine) == 1 && fCurrentLine[0] == '\n',
"Expect '\n' as only character in this line"); "Expect '\n' as only character in this line");
nextChunkStartsWithNewline = false; fNextChunkStartsWithNewline = false;
} }
} }
} }
@ -3253,7 +3253,7 @@ bool nsImapServerResponseParser::msg_fetch_literal(bool chunk, int32_t origin)
} }
else else
{ {
nextChunkStartsWithNewline = false; fNextChunkStartsWithNewline = false;
} }
return lastChunk; return lastChunk;
} }

View file

@ -256,6 +256,9 @@ private:
int32_t charsReadSoFar; int32_t charsReadSoFar;
bool fLastChunk; bool fLastChunk;
// Flags split of \r and \n between chunks in msg_fetch_literal().
bool fNextChunkStartsWithNewline;
// points to the current body shell, if any // points to the current body shell, if any
RefPtr<nsIMAPBodyShell> m_shell; RefPtr<nsIMAPBodyShell> m_shell;