Closed
Bug 273025
Opened 20 years ago
Closed 15 years ago
bad logic results in potential leak xor crash based on flow
Categories
(Core Graveyard :: Plug-ins, defect)
Core Graveyard
Plug-ins
Tracking
(Not tracked)
RESOLVED
FIXED
mozilla1.9.3a1
People
(Reporter: timeless, Assigned: mwu)
References
()
Details
(Keywords: memory-leak)
Attachments
(2 files, 8 obsolete files)
|
15.75 KB,
patch
|
Details | Diff | Splinter Review | |
|
17.68 KB,
patch
|
Details | Diff | Splinter Review |
the url contains code flow analysis. if you're interested in fixing this bug,
other developers on irc will gladly help.
there are two bugs here.
1. if {headers#118} and {!NS_SUCCEEDED(rv)#125} then buf#120 leaks.
2. if {!headers#118} and {NS_SUCCEEDED(rv)#125} then AdoptData#126 is an api
violation and should eventually lead to a crash
Comment 1•18 years ago
|
||
So... I tried to sort through this, but the plug-in code is completely schizoid about who owns what data. None of it is documented, and I got lost in a maze of twisty functions, all with similar names.... :(
Flags: blocking1.9?
Comment 2•18 years ago
|
||
Specifically, what is the API contract for ownership of the POST data strings going across NPN_PostURL and such?
Flags: blocking1.9? → blocking1.9-
Whiteboard: [wanted-1.9]
| Assignee | ||
Comment 3•18 years ago
|
||
This code is.. interesting. One of the callers of NewPluginURLStream (which ends up calling NS_NewPluginPostDataStream) frees the string buffer it passes to NewPluginURLStream based on if isFile is true. This is no good since an error can cause the string to get leaked. Need to investigate other callers and possibly some plugins code to figure out if this fix is the right idea.
Assignee: nobody → michael.wu
Status: NEW → ASSIGNED
Comment 4•18 years ago
|
||
Almost definitely need to look at some plugins' code: they'd be calling NPN_PostURL.
| Assignee | ||
Comment 5•18 years ago
|
||
Comment on attachment 274245 [details] [diff] [review]
Possible fix, v1
Alright, I've investigated a bit further and I'm pretty sure there's no problem with AdoptData - in all cases, it's allocated correctly by us. However, there are quite a number of ways to leak the post data if errors occur.
Attachment #274245 -
Attachment is obsolete: true
| Assignee | ||
Comment 6•18 years ago
|
||
This patch is just code cleanups. The behavior of the code should not change at all. This just made it easier for me to read the code and put together the patch that actually fixes this bug.
Attachment #275012 -
Flags: superreview?(cbiesinger)
Attachment #275012 -
Flags: review?(jst)
Comment 7•18 years ago
|
||
Michael, could you attach a diff -w here to make reviewing a bit easier?
| Assignee | ||
Comment 8•18 years ago
|
||
And this patch actually fixes the bug, by refactoring much of the code. This should fix a large number of potential memory leaks when using PostURL and make it much more clear who owns what.
It fixes:
1. A potential leak of dataToPost (in PostURL) if the function it's passed to does not free the string on error. (either NewPluginURLStream or GetURL - and they almost never free the string on an error) This is achieved by giving the string data to a nsIStringInputStream ASAP and passing that input stream around instead. This also eliminates the NS_NewPluginPostDataStream function.
2. A potential leak of listenerPeer in the error path by using a nsRefPtr.
3. A leak of the tmpfile string returned by CreateTmpFileToPost. A nsIFile is now returned instead, which is more efficient and leak resistant.
Attachment #275014 -
Flags: superreview?(cbiesinger)
Attachment #275014 -
Flags: review?(jst)
| Assignee | ||
Comment 9•18 years ago
|
||
(In reply to comment #8)
> Created an attachment (id=275014) [details]
> Improve GetURL/PostURL code, v1, (2/2)
>
Oh, and one last bug this fixes:
4. A potential failure to delete the temporary file due to errors. The temporary file is now opened as soon as possible to ensure it gets deleted at some point.
| Assignee | ||
Comment 10•18 years ago
|
||
(In reply to comment #7)
> Michael, could you attach a diff -w here to make reviewing a bit easier?
>
Most of it wasn't just whitespace changes, so it doesn't seem to change much with -w.
| Assignee | ||
Updated•18 years ago
|
| Reporter | ||
Comment 11•18 years ago
|
||
Comment on attachment 275014 [details] [diff] [review]
Improve GetURL/PostURL code, v1, (2/2)
nsPluginInstanceOwner::GetURL - line too long
createTmpFileToPost - please spell out Temp since we're already changing the api
nsIFile **pTmpFile - args should be aFoo
you can do NS_ADDREF(*aTempFile = tempFile)
thanks for working on this.
i don't suppose you would be interested in making test plugins :).
| Assignee | ||
Comment 12•18 years ago
|
||
Just some unbitrotting.
Attachment #275012 -
Attachment is obsolete: true
Attachment #276507 -
Flags: superreview?(jst)
Attachment #276507 -
Flags: review?(jst)
Attachment #275012 -
Flags: superreview?(cbiesinger)
Attachment #275012 -
Flags: review?(jst)
| Assignee | ||
Comment 13•18 years ago
|
||
Address timeless' comments.
Attachment #276507 -
Attachment is obsolete: true
Attachment #276508 -
Flags: superreview?(jst)
Attachment #276508 -
Flags: review?(jst)
Attachment #276507 -
Flags: superreview?(jst)
Attachment #276507 -
Flags: review?(jst)
| Assignee | ||
Updated•18 years ago
|
Attachment #275014 -
Attachment is obsolete: true
Attachment #275014 -
Flags: superreview?(cbiesinger)
Attachment #275014 -
Flags: review?(jst)
| Assignee | ||
Updated•18 years ago
|
Attachment #276507 -
Attachment is obsolete: false
Attachment #276507 -
Flags: superreview?(jst)
Attachment #276507 -
Flags: review?(jst)
Comment 14•17 years ago
|
||
Ping - is this bug still live? Asking because it is on the leaks list...
Comment 15•17 years ago
|
||
Given how fragile this code is I don't think we should bother with this for 1.9 unless someone can show that this is a source for a non-trivial amount of leaks. We've fixed leaks around this code before and caused plugins to break, which led us to undo the leak fix...
That sounds ok to me. It's something we should keep in mind once we start doing trace-malloc testing and plugins.
| Reporter | ||
Comment 17•17 years ago
|
||
this is only a leak if you're already out of memory (which happens often for embedders but rarely in most other environments).
unfortunately my group is being bugged by people who intentionally run our device out of memory and then complain about leaks and bad behavior.
so technically i care.
jst: could you please review this? it isn't fare to the assignee that you haven't and it isn't fair to anyone else. it's also a bad example to people who might want to contribute showing how little we apparently care about contributions.
i'm fine with not committing this (for 1.9), but i think you at least owe michael the review (and any of us the chance to use the reviewed patch in our modified variants instead of encouraging people to randomly include unreviewed patches).
Updated•17 years ago
|
Flags: wanted1.9+
Whiteboard: [wanted-1.9]
| Assignee | ||
Comment 18•16 years ago
|
||
Updated to mozilla-central. This patch does less than before due to cleanups in nsPluginHost.
Attachment #276507 -
Attachment is obsolete: true
Attachment #276507 -
Flags: superreview?(jst)
Attachment #276507 -
Flags: review?(jst)
| Assignee | ||
Comment 19•16 years ago
|
||
Same thing without all the indentation changes that confuse diff.
Attachment #402000 -
Flags: superreview?(jst)
Attachment #402000 -
Flags: review?(jst)
| Assignee | ||
Comment 20•16 years ago
|
||
Updated to mozilla-central. Note that this bug doesn't just leak when you're out of memory - it leaks even when you have memory and no errors occur. (#3 in https://bugzilla.mozilla.org/show_bug.cgi?id=273025#c8 )
Attachment #276508 -
Attachment is obsolete: true
Attachment #276508 -
Flags: superreview?(jst)
Attachment #276508 -
Flags: review?(jst)
| Assignee | ||
Comment 21•16 years ago
|
||
Holding off the review request for the second patch until I convince myself I remember what the code was trying to do before.
Comment 22•16 years ago
|
||
Comment on attachment 402003 [details] [diff] [review]
Improve GetURL/PostURL code, v3, (2/2)
r+sr=jst for this cleanup (indentation changes should of course be included when checking in). Now's a pretty good time to do the commit the rest of this fix as well.
Attachment #402003 -
Flags: superreview+
Attachment #402003 -
Flags: review+
Comment 23•16 years ago
|
||
Comment on attachment 402003 [details] [diff] [review]
Improve GetURL/PostURL code, v3, (2/2)
Er, wrong attachment.
Attachment #402003 -
Flags: superreview+
Attachment #402003 -
Flags: review+
Updated•16 years ago
|
Attachment #402000 -
Flags: superreview?(jst)
Attachment #402000 -
Flags: superreview+
Attachment #402000 -
Flags: review?(jst)
Attachment #402000 -
Flags: review+
| Assignee | ||
Comment 24•16 years ago
|
||
Applies cleanly against mozilla-central. Gonna mark checkin-needed since I have no idea how commits work in this post-cvs world.
Attachment #401999 -
Attachment is obsolete: true
Attachment #402000 -
Attachment is obsolete: true
| Assignee | ||
Updated•16 years ago
|
Keywords: checkin-needed
| Assignee | ||
Comment 25•15 years ago
|
||
Comment on attachment 402003 [details] [diff] [review]
Improve GetURL/PostURL code, v3, (2/2)
Ok I figured out what I did and it looks fine. Mochitests pass too, though the tests (bug 517078) don't cover the PostURL file=true codepath.
Attachment #402003 -
Flags: superreview?(jst)
Attachment #402003 -
Flags: review?(jst)
Comment 26•15 years ago
|
||
Comment on attachment 408225 [details] [diff] [review]
Improve GetURL/PostURL code, v4, (1/2)
[Checkin: Comment 26]
http://hg.mozilla.org/mozilla-central/rev/fa0a3e9b1f54
Attachment #408225 -
Attachment description: Improve GetURL/PostURL code, v4, (1/2) For checkin → Improve GetURL/PostURL code, v4, (1/2)
[Checkin: Comment 26]
Updated•15 years ago
|
Keywords: checkin-needed
Target Milestone: mozilla1.9alpha8 → mozilla1.9.3a1
Comment 27•15 years ago
|
||
Comment on attachment 402003 [details] [diff] [review]
Improve GetURL/PostURL code, v3, (2/2)
- In nsPluginInstanceOwner::GetURL():
+ if (aHeadersDataLen <= 0)
aHeadersDataLen is unsigned, so use !aHeadersDataLen or aHeadersDataLen == 0 here.
+ char *buf = (char *)nsMemory::Alloc(aHeadersDataLen);
+ if (!buf)
+ return NS_ERROR_OUT_OF_MEMORY;
+ memcpy(buf, aHeadersData, aHeadersDataLen);
+
+ nsCOMPtr<nsIStringInputStream> sis = do_CreateInstance("@mozilla.org/io/string-input-stream;1");
+ if (!sis) {
+ NS_Free(buf);
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+
+ sis->AdoptData(buf, aHeadersDataLen);
All of the above could be replaced with a call to sis->SetData((char *)aHEadersData, aHeadersDataLen) no?
- In nsPluginHost::PostURL():
// we use nsIStringInputStream::adoptDataa()
// in NS_NewPluginPostDataStream to set the stream
// all new data alloced in ParsePostBufferToFixHeaders()
// well be nsMemory::Free()d on destroy the stream
Update this comment, NS_NewPluginPostDataStream() no longer exists after this patch.
- In nsPluginHost::CreateTempFileToPost():
+ NS_ADDREF(*aTmpFile = tempFile);
Maybe do *aTmpFile = tempFile.forget().get() here instead to avoid extra refcounting?
r=jst with that looked into.
Attachment #402003 -
Flags: superreview?(jst)
Attachment #402003 -
Flags: superreview+
Attachment #402003 -
Flags: review?(jst)
Attachment #402003 -
Flags: review+
| Assignee | ||
Comment 28•15 years ago
|
||
All review comments addressed. Thanks jst!
Attachment #402003 -
Attachment is obsolete: true
Updated•15 years ago
|
Keywords: checkin-needed
Comment 29•15 years ago
|
||
Updated•3 years ago
|
Product: Core → Core Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•