Closed Bug 248933 Opened 20 years ago Closed 20 years ago

IMAP parser: end of line is not handled correctly while parsing quoted/literal strings

Categories

(MailNews Core :: Networking: IMAP, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: engel, Assigned: engel)

References

Details

Attachments

(1 file, 1 obsolete file)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040622
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040622

The logic of the imap parser is to set an 'end-of-line' flag if |fNextToken|
corresponds to the end of the line.  However, in the current implementation of
|CreateQuoted| and |CreateLiteral|, the 'end-of-line' flag is set according to
the token *after* |fNextToken| (i.e., this code checks if
|fCurrentTokenPlaceHolder| is at the end of the line).  This should be made
consistent.

The correct parser usage is to call |CreateQuoted|/|CreateLiteral|, then
|GetNextToken| and finally to check for the end-of-line condition.  This is
currently implemented this way in all the imap parser code, so no change is
required outside |CreateQuoted|/|CreateLiteral|.

Due to this incorrect end-of-line handling, a kludge was used in
nsImapServerResponseParser.cpp, where the |fAtEndOfLine| was reset by hand. 
This kludge can be removed while fixing this bug.

Finally, in |CreateLiteral| for some special cases, the behavior beyond the
end-of-line issue is also broken.

In addition, there is a bug in |CreateLiteral| when a 'static buffer' is used
and the current line does not contain the whole literal (a very unlikely case).
 For example, if the current line is "{9}\r\n\nxyz\r\n", |CreateLiteral| will 
return the string "\nxyz\r\nxyz"; i.e., partially duplicating the input.  This
bug can easily be fixed while fixing the bugs described above.

Reproducible: Always
Steps to Reproduce:
These issues outlined above should be fixed with this patch.

Note that we can remove two extra lines, because
|AdvanceTokenizerStartingPoint| recovers all 'token boundaries' and so the
condition |if (!*fCurrentTokenPlaceHolder)| is always false.
Confirming.  While I can't read code, someone should look at the patch...Hans,
feel free to set reviews.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Hans: Get David Bienvenu to review it.
Attachment #151877 - Flags: review?(bienvenu)
Comment on attachment 151877 [details] [diff] [review]
fixing CreateQuoted and CreateLiteral in IMAPGenericParser, removing kludge in ImapServerResponseParser

This breaks for  the very pathological case "{4}\r\nL2\r\nA3\r\n". Note, ther
is no space before A3, thus it probably not a valid imap input.  But let us fix
this anyway.  New patch forthcoming.
Attachment #151877 - Attachment is obsolete: true
Attachment #151877 - Flags: review?(bienvenu)
see comment #1 and comment #4

Added 2x |AdvanceTokenizerStartingPoint(0)| to the patch.  This handles more
(hopefully all) special cases correctly.
Attachment #151896 - Flags: review?(bienvenu)
I'm on vacation - I'll have to try this when I get back. It might take me a week
to get to this - thx for looking into it.
Blocks: 249999
Attachment #151896 - Flags: review?(bienvenu) → review+
Status: NEW → ASSIGNED
Attachment #151896 - Flags: superreview?(sspitzer)
Assignee: bienvenu → Hans-A.Engel
Status: ASSIGNED → NEW
Status: NEW → ASSIGNED
Attachment #151896 - Flags: superreview?(sspitzer) → superreview?(neil.parkwaycc.co.uk)
Attachment #151896 - Flags: superreview?(neil.parkwaycc.co.uk) → superreview?(dmose)
Comment on attachment 151896 [details] [diff] [review]
fixing CreateQuoted and CreateLiteral in IMAPGenericParser, removing kludge in ImapServerResponseParser, v2

sr=dmose
Attachment #151896 - Flags: superreview?(dmose) → superreview+
Timeless checked in the 2nd patch, marking FIXED.
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Product: MailNews → Core
Blocks: 313038
Product: Core → MailNews Core
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: