Closed
Bug 157994
Opened 21 years ago
Closed 19 years ago
Code in in nsDataObj.cpp prone to buffer overflow , and generally awful
Categories
(Core :: XUL, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: sfraser_bugs, Assigned: daniel_atallah)
References
()
Details
(Keywords: fixed1.7.5)
Attachments
(1 file, 3 obsolete files)
4.50 KB,
patch
|
dean_tessman
:
review+
sfraser_bugs
:
superreview+
asa
:
approval-aviary-
mkaply
:
approval1.7.5+
|
Details | Diff | Splinter Review |
The code in nsDataObj::BuildPlatformHTML(), which is called when copying to the clipboard on Windows, has a slew of evil strcpy, strcat and wsprintf calls. It's also bug-prone, if the copied content contains "<!--EndFrag".
Comment 2•21 years ago
|
||
Actually, I take that back. This should be fixed. It's just not high on my list of things to fix, so if there are any volunteers out there ... :-)
Keywords: helpwanted
Target Milestone: Future → ---
Comment 3•21 years ago
|
||
There's no overflow risk here. We allocate 400 bytes _plus_ the length of the HTML, which is more than enough to handle the start and end fragments. The concern about a pre-existing "<!-- EndFragment -->" is valid, and can certainly be handled better than we are currently.
Target Milestone: --- → Future
Comment 4•21 years ago
|
||
Actually, i think we do this wrong anyway. StartFragment:<n> should point to the first character _after_ "<!-- StartFragment -->". If I copy text from Moz and paste it into an HTML message in Outlook Express, the source contains "<!-- StartFragment -->". Filed bug 158103 for that, to be fixed after this is fixed.
Reporter | ||
Comment 5•21 years ago
|
||
It would be so easy to rewrite the code to use simple, safe nsString routines, and eliminate all the strcat, and strstr calls. This code will show up as a hotspot in security code reviews (since the tools look for 'dangerous' routines like strcpy, strcat, and routines in the printf family). Do yourself a favour; rewrite the code, and get it off the radar.
Comment 6•21 years ago
|
||
sure, rewrite it. it's nasty code anyway and i'm not terribly proud of it ;)
Comment 7•21 years ago
|
||
But if we re-write it, how will we blame Pinkerton for this nasty code? :)
Reporter | ||
Comment 9•21 years ago
|
||
Comment on attachment 91848 [details] [diff] [review] draft oh god no please
Attachment #91848 -
Flags: needs-work+
Comment 10•21 years ago
|
||
Is the crash in bug 158002 related? The stack pasted looks like garbage, but it does mention pasting. Others have had difficulty reproducing it, though.
Comment 11•21 years ago
|
||
ok, sfraser wants this to use mozilla string classes. blah
Reporter | ||
Comment 12•21 years ago
|
||
Untested patch more along the lines of what I was thinking.
Comment 13•21 years ago
|
||
+ const char* const numPlaceholder = "00000000"; + const char* const startHTMLPrefix = "Version:0.9\r\nStartHTML:"; + const char* const endHTMLPrefix = "\r\nEndHTML:"; + const char* const startFragPrefix = "\r\nStartFragment:"; + const char* const endFragPrefix = "\r\nEndFragment:"; + const char* const endFragTrailer = "\r\n"; Why two consts? Is there any chance of commenting the code that builds the final version. It's not ugly as the current version, but it's still a little confusing to try and read through.
Reporter | ||
Comment 14•21 years ago
|
||
const char* const testString = "foopy"; testString ++; // compile error *testString = 0; // compile error const char* testString2 = "foopy"; testString2 ++; // OK! *testString2 = 0; // compile error
Comment 15•21 years ago
|
||
char* testString2 = "foopy"; testString2 ++; // OK! *testString2 = 0; // OK!
Reporter | ||
Comment 16•21 years ago
|
||
char* testString2 = "foopy"; *testString2 = 0; // OK! yes, but this will probably crash your program. You might have got a compiler error, or at least a warning, on the first line.
Comment 17•21 years ago
|
||
|const char* testString = "foopy"| is what we typically use; since "foopy" may end up in read-only memory, it's safest to reflect that in your pointer by saying the pointer is of type |const char| and thus whatever it points to can't be changed. However, the pointer itself could still be changed in this case, e.g. to point to another literal. By marking it |const char* const testString = "foopy"| you're not only saying that the literal text can't be changed, you're also saying that you have no intention of changing the pointer. These |const|s will help the compiler catch any mistakes you or someone else makes (|*testString = 0;|) and it allows the compiler to optimize the pointer away where possible.
Reporter | ||
Comment 18•21 years ago
|
||
That's exactly what I was trying to demonstrate by example. Thank you, jag!
Comment 19•20 years ago
|
||
Comment on attachment 91866 [details] [diff] [review] Untested patch so does this work, and are we ok with it?
Attachment #91866 -
Flags: superreview?(jaggernaut)
Attachment #91866 -
Flags: review?(dean_tessman)
Comment 20•20 years ago
|
||
Do you want to address bug 158103 at the same time? All you'd need to do is change how you're calculating startFragOffset.
Comment 21•20 years ago
|
||
well since jag isn't working on this, and dean responded first :)
Assignee: jaggernaut → dean_tessman
Target Milestone: Future → ---
Comment 22•20 years ago
|
||
Comment on attachment 91866 [details] [diff] [review] Untested patch Couldn't we do something here with nsPrintfCString("%08u", len)?
Assignee | ||
Comment 23•19 years ago
|
||
At Dean Tessman's suggestion, I incorporated the bug fix for Bug 158103 as well as the cleanup for this bug (Bug 157994) into a patch. This is based on timeless' patch with changes to fix 158103 and to use the cleaner nsPrintfCString() that jag suggested.
Comment 24•19 years ago
|
||
Comment on attachment 158507 [details] [diff] [review] Proposed patch to cleanup and fix the win32 HTML Clipboard population >+/* >+ nsDependentCString headerString( >+ "Version:0.9\r\n" >+ "StartHTML:00000000\r\n" // offset of <html> >+ "EndHTML:00000000\r\n" // offset of end of </html> >+ "StartFragment:00000000\r\n" // offset of end of <!--StartFragment--> >+ "EndFragment:00000000\r\n" // offset of <!--EndFrag >+ ); >+*/ Remove this. >+ nsCAutoString numString; >+ numString.AppendInt(startHTMLOffset); This isn't used anywhere. >+ nsCString clipboardString; One too many spaces here. >+ *outPlatformHTML = ToNewCString(clipboardString);printf("outPlatformHTML='%s'\n", outPlatformHTML); Remove the printf. Other than that it looks much better than what we have. r=me
Attachment #158507 -
Flags: superreview?(jag)
Attachment #158507 -
Flags: review+
Assignee | ||
Comment 25•19 years ago
|
||
I incorporated the changes suggested by Dean. (the printf wasn't supposed to be in the final version of the previous patch!)
Comment 26•19 years ago
|
||
Comment on attachment 158549 [details] [diff] [review] Update of proposed patch to cleanup and fix the win32 HTML Clipboard population Carrying forward flags.
Attachment #158549 -
Flags: superreview?(jag)
Attachment #158549 -
Flags: review+
Updated•19 years ago
|
Attachment #91848 -
Attachment is obsolete: true
Updated•19 years ago
|
Attachment #91866 -
Attachment is obsolete: true
Updated•19 years ago
|
Attachment #158507 -
Attachment is obsolete: true
Comment 27•19 years ago
|
||
+ nsDependentCString htmlHeaderString("<html><body>\r\n"); NS_NAMED_LITERAL_CSTRING(htmlHeaderString, "<html>...."); is slightly faster (calculates length at compile time)
Comment 28•19 years ago
|
||
Jag, are you OK with the patch if the change in comment 27 is made?
Assignee: dean_tessman → daniel_atallah
Reporter | ||
Updated•19 years ago
|
Attachment #158549 -
Flags: superreview?(jag) → superreview+
Comment 29•19 years ago
|
||
Comment on attachment 158549 [details] [diff] [review] Update of proposed patch to cleanup and fix the win32 HTML Clipboard population Do we want this on the aviary branch as well?
Attachment #158549 -
Flags: approval-aviary?
Assignee | ||
Comment 30•19 years ago
|
||
Comment on attachment 158549 [details] [diff] [review] Update of proposed patch to cleanup and fix the win32 HTML Clipboard population I think that this is important to also get into the Aviary-1.0 branch and SeaMonkey, particularly because it fixes Bug 158103.
Attachment #158549 -
Flags: approval1.7.x?
Updated•19 years ago
|
Flags: blocking-aviary1.0?
Comment 31•19 years ago
|
||
we may still approve the patch, but not going to block on this.
Flags: blocking-aviary1.0? → blocking-aviary1.0-
Comment 32•19 years ago
|
||
jst says this isn't critical for the branch. dean, what's the risk here?
Comment 33•19 years ago
|
||
Comment on attachment 158549 [details] [diff] [review] Update of proposed patch to cleanup and fix the win32 HTML Clipboard population (In reply to comment #32) > jst says this isn't critical for the branch. dean, what's the risk here? I agree that it's not critical, but I thought I'd ask. Clearing branch request flags.
Attachment #158549 -
Flags: approval1.7.x?
Attachment #158549 -
Flags: approval-aviary?
Assignee | ||
Comment 34•19 years ago
|
||
I'm not familiar with the criteria for determining what is considered critical and what isn't, but I would venture to say that in my opinion, this fix should go into the aviary branch because the current win32 HTML copying functionality is somewhat broken. Bug 158103 describes the issues that it suffers from in detail, but basically, if what is placed into the HTML copy buffer is pasted directly, there is a garbage "<!--StartFragment-->" at the beginning of the pasted segment. Thankfully most applications just ignore it because it is a HTML comment, but it is still pasted. Don't we want to have fully functional win32 copy/paste functionality in FireFox 1.0?
Comment 35•19 years ago
|
||
Comment on attachment 158549 [details] [diff] [review] Update of proposed patch to cleanup and fix the win32 HTML Clipboard population > Don't we want to have fully functional win32 copy/paste functionality in > FireFox 1.0? I forgot about that part of the fix. I was concentrating only on the potential overflow. The copied HTML doesn't mess up the HTML output at all, since <!--StartFragment--> is a self-contained comment. That being said, I don't think we want to get lambasted for propogating that comment into web pages, emails, etc. Putting back approval requests to let someone with decision-making power flex said power.
Attachment #158549 -
Flags: approval1.7.x?
Attachment #158549 -
Flags: approval-aviary?
Updated•19 years ago
|
Attachment #91866 -
Flags: superreview?(jag)
Attachment #91866 -
Flags: review?(dean_tessman)
Comment 36•19 years ago
|
||
Comment on attachment 158549 [details] [diff] [review] Update of proposed patch to cleanup and fix the win32 HTML Clipboard population a=mkaply for the branches. Don't forget to dupe the other bug to this. Has this patch gone in on the trunk?
Attachment #158549 -
Flags: approval1.7.x?
Attachment #158549 -
Flags: approval1.7.x+
Attachment #158549 -
Flags: approval-aviary?
Attachment #158549 -
Flags: approval-aviary+
Comment 37•19 years ago
|
||
(In reply to comment #36) > Has this patch gone in on the trunk? Not that I've seen.
Updated•19 years ago
|
Attachment #158507 -
Flags: superreview?(jag)
Comment 38•19 years ago
|
||
Comment on attachment 158549 [details] [diff] [review] Update of proposed patch to cleanup and fix the win32 HTML Clipboard population mozilla/widget/src/windows/nsDataObj.cpp 1.64 mozilla/widget/src/windows/nsDataObj.cpp 1.59.16.1
Assignee | ||
Comment 39•19 years ago
|
||
Bump... (reminder that this still needs to be committed/merged to the AVIARY branch). (FF 1.0 release date is fast approaching and i'm looking forward to having this in there)
Comment 40•19 years ago
|
||
> mozilla/widget/src/windows/nsDataObj.cpp 1.59.16.1
since this fixed this on the 1.7 branch, adding keyword.
should this bug be marked fixed now that the patch is checked in, or is there
more to do?
Keywords: helpwanted → fixed1.7.x
Comment 41•19 years ago
|
||
Comment on attachment 158549 [details] [diff] [review] Update of proposed patch to cleanup and fix the win32 HTML Clipboard population This hasn't gone in on the aviary branch. We had approval once but didn't get it checked in in time. Re-requesting approval for 1.0.
Attachment #158549 -
Flags: approval-aviary+ → approval-aviary?
Comment 42•19 years ago
|
||
Comment on attachment 158549 [details] [diff] [review] Update of proposed patch to cleanup and fix the win32 HTML Clipboard population too late for 1.0
Attachment #158549 -
Flags: approval-aviary? → approval-aviary-
Assignee | ||
Comment 43•19 years ago
|
||
(In reply to comment #41) > (From update of attachment 158549 [details] [diff] [review]) > This hasn't gone in on the aviary branch. We had approval once but didn't get > it checked in in time. Re-requesting approval for 1.0. > Can this fixe be merged to the aviary branch now so that this bug and Bug 158103 can be closed? (or do we want to just close them because it has been committed to HEAD?)
Assignee | ||
Comment 44•19 years ago
|
||
The fix has been committed to everywhere that it needs to be at this time, as far as I can tell.
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•