Open Bug 227679 Opened 21 years ago Updated 3 years ago

<nsMsgUtils.cpp>: Fix improper handling of |end| in escaping "From " line functions

Categories

(MailNews Core :: Import, defect)

defect

Tracking

(Not tracked)

ASSIGNED

People

(Reporter: sgautherie, Assigned: sgautherie)

References

Details

Attachments

(5 obsolete files)

Spun off from bug 119441 attachement 66959. May be I haven't worked with pointers for too long, or that code is incorrect. Anyway, I'll post a patch, and welcome comments.
Attached patch (Av1) <nsMsgUtils.cpp> (obsolete) — Splinter Review
The initial assumption is that |end| points beyond the last buffer character, then |*end| must not be accessed. Actually, I kind of "rewrote" the 2 involved functions.
Attachment #136956 - Flags: superreview?(sspitzer)
Attachment #136956 - Flags: review?(ducarroz)
Status: NEW → ASSIGNED
Attached patch (Av1b) <nsMsgUtils.cpp> (obsolete) — Splinter Review
'r=?': (see comment 0 and comment 1) Can you (super-)review, compile, test, check it in ?
Attachment #136956 - Attachment is obsolete: true
Attachment #136956 - Flags: superreview?(sspitzer)
Attachment #136956 - Flags: review?(ducarroz)
Comment on attachment 136971 [details] [diff] [review] (Av1b) <nsMsgUtils.cpp> (see comment 2)
Attachment #136971 - Flags: superreview?(sspitzer)
Attachment #136971 - Flags: review?(ducarroz)
Attached patch (Av1c) <nsMsgUtils.cpp> (obsolete) — Splinter Review
Attachment #136971 - Attachment is obsolete: true
Attachment #136971 - Flags: superreview?(sspitzer)
Attachment #136971 - Flags: review?(ducarroz)
Comment on attachment 136974 [details] [diff] [review] (Av1c) <nsMsgUtils.cpp> 'r=?': (see comment 0 and comment 1) Can you (super-)review, compile, test, check it in ?
Attachment #136974 - Flags: superreview?(sspitzer)
Attachment #136974 - Flags: review?(ducarroz)
Attachment #136974 - Flags: review?(ducarroz) → review?(bienvenu)
+ // Optimization: direct 'F' test, followed by |strncmp()| call. + if ((end - start >= 5) && (*start == 'F') && !strncmp(start + 1, "rom ", 4)) rv = PR_TRUE; + return rv; can't this just be: return ((end - start >= 5) && (*start == 'F') && !strncmp(start + 1, "rom ", 4)); and get rid of rv completely? if nsIFileSpec &pDst is a ref ptr, then this shouldn't compile, right? + rv = pDst->Write(">", 1, &written); pDst.Write(">", 1, &written); Is this the code that could access one byte past the end? : - while ((pChar < end) && (*pChar != nsCRT::CR) && (*(pChar+1) != nsCRT::LF)) seems like there could be a safer fix if that's the only actual problem...
Attached patch (Av1d) <nsMsgUtils.cpp> (obsolete) — Splinter Review
Patch Av1c, plus comment 6 suggestions. The 2 memory access issues were: |- if ( (*start == 'F') && (end-start > 4) && !strncmp(start, "From ", 5) )| We may have |start == end|, then |end-start| check must come first. |- while ((pChar < end) && (*pChar != nsCRT::CR) && (*(pChar+1) != nsCRT::LF))| Yes, we may have |(pChar+1) == end|. Also, the |0CR && 1LF| seems odd... while |0CR || 1LF| is more explicit. All the rest is rewriting/"optimization"... What safer fix are you thinking about ?
Attachment #137055 - Flags: superreview?(sspitzer)
Attachment #137055 - Flags: review?(bienvenu)
Attachment #136974 - Attachment is obsolete: true
Attachment #136974 - Flags: superreview?(sspitzer)
Attachment #136974 - Flags: review?(bienvenu)
Attachment #136956 - Attachment description: (Av1) <nsMsgUtils.cpp> patch → (Av1) <nsMsgUtils.cpp>
Attachment #136974 - Attachment description: (Av1c) <nsMsgUtils.cpp> patch → (Av1c) <nsMsgUtils.cpp>
Attachment #136971 - Attachment description: (Av1b) <nsMsgUtils.cpp> patch → (Av1b) <nsMsgUtils.cpp>
by safer, I meant "less lines of code changed", not that your changes are particularly dangerous. I haven't had a chance to compile or test your changes but I'll try to do it soon.
Attached patch (Av1e) <nsMsgUtils.cpp> (obsolete) — Splinter Review
(==) Av1d, with trunk update.
Attachment #137055 - Attachment is obsolete: true
Attachment #137055 - Flags: superreview?(sspitzer)
Attachment #137055 - Flags: review?(bienvenu)
Comment on attachment 137955 [details] [diff] [review] (Av1e) <nsMsgUtils.cpp> I have no compiler: Could you compile/test/review it ? Thanks.
Attachment #137955 - Flags: review?(bienvenu)
Target Milestone: --- → mozilla1.7alpha
Target Milestone: mozilla1.7alpha → ---
Product: MailNews → Core
Comment on attachment 137955 [details] [diff] [review] (Av1e) <nsMsgUtils.cpp> This patch is obsolete since the file spec removal happened. If someone wants to resurrect, and compile and test their changes, then we could move forward. From what I can tell, this code is only used by import.
Attachment #137955 - Attachment is obsolete: true
Attachment #137955 - Flags: review?(bienvenu)
QA Contact: nbaca → import
Product: Core → MailNews Core
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: