Closed Bug 660066 Opened 14 years ago Closed 14 years ago

Crash when comparing a moz-filedata: URI with null principal

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED
mozilla7

People

(Reporter: dholbert, Assigned: dholbert)

References

Details

(Keywords: crash)

Attachments

(3 files, 1 obsolete file)

I just tried adding a moz-filedata URI to the xpcshell test test_URIs.js, and it crashed due to nsFileDataURI::EqualsInternal() dereferencing mPrincipal when mPrincipal is null. It looks like other places in nsFileDataURI have null-checks for mPrincipal, e.g. > 184 nsFileDataURI::GetPrincipalUri(nsIURI** aUri) > 185 { > 186 if (mPrincipal) { > 187 mPrincipal->GetURI(aUri); > 188 } > 189 else { > 190 *aUri = nsnull; > 191 } so EqualsInternal needs to handle a null mPrincipal, too. Have patch in hand, just polishing/testing.
Keywords: crash
This patch just adds some more URIs to test_URIs.js. These ones all pass. Posting them here for lack of a better place to put them, and because the moz-file: test addition layers on top of these. (touches same contextual code)
Attachment #535471 - Flags: review?(bzbarsky)
Here's the fix. It allows for null mPrincipal, and makes the ::EqualsInternal logic more similar to nsJSURI::EqualsInternal. (Note that I avoid passing null to nsPrincipal::Equals() -- technically it can handle a null value, but it spams a NS_WARNING to stderr, which we probably don't need/want here. (I think?)) I also extended test_URIs to test the "uri.Equals(null)" behavior on all of the URI testcases there. Some Equals impls throw when passed null (e.g. nsSimpleURI, nsStandardURL) whereas others just return false (e.g. nsSimpleNestedURI, nsFileDataURI). Eventually we should probably make that consistent, but for now the test just checks that we do one of those two reasonable things.
Attachment #535476 - Flags: review?(bzbarsky)
Comment on attachment 535471 [details] [diff] [review] patch 0: add more test_URIs.js testcases r=me
Attachment #535471 - Flags: review?(bzbarsky) → review+
Comment on attachment 535476 [details] [diff] [review] patch 1: fix + test for this bug >+ if (!nsSimpleURI::EqualsInternal(otherJSURI, aRefHandlingMode)) { otherFileDataUri, yes? Did you compile this? ;) >+ *aResult = (!mPrincipal && !otherFileDataUri->mPrincipal); Alternately, *aResult = (mPrincipal == otherFileDataUri->mPrincipal); r=me either way as long as you fix the otherJSURI thing. While you're here, do you want to change the QI in filedata to not QI to the nsSimpleURI CID and add a test for that?
Attachment #535476 - Flags: review?(bzbarsky) → review+
(In reply to comment #4) > Comment on attachment 535476 [details] [diff] [review] [review] > patch 1: fix + test for this bug > > >+ if (!nsSimpleURI::EqualsInternal(otherJSURI, aRefHandlingMode)) { > > otherFileDataUri, yes? Did you compile this? ;) Oops! I transferred that bit of logic (replacing a call to the superclass's normal EqualsInternal method) right before posting, and I swear I recompiled & retested, but I may have accidentally used my standard rebuild-dirs-that-I-frequently-touch script, which doesn't include /dom. Thanks for catching that. :)
(er s/dom/content/)
(In reply to comment #4) > While you're here, do you want to change the QI in filedata to not QI to the > nsSimpleURI CID and add a test for that? Here's patch & test for that. Confirmed that it compiles ;) and that the test fails before the code-change & passes after.
Attachment #535568 - Flags: review?(bzbarsky)
(cleaned up the test in patch 2 slightly, refactoring the [in]equality checks out into a helper method)
Attachment #535568 - Attachment is obsolete: true
Attachment #535568 - Flags: review?(bzbarsky)
Attachment #535724 - Flags: review?(bzbarsky)
Landed patches 0 and 1, since they don't really depend on patch 2 at all. http://hg.mozilla.org/projects/cedar/rev/2d6730eb0852 http://hg.mozilla.org/projects/cedar/rev/0173afbf1e62 Will land patch 2 once it's gotten r+.
Whiteboard: fixed-in-cedar
Target Milestone: --- → mozilla7
Comment on attachment 535724 [details] [diff] [review] patch 2 v2: keep nsFileDataURI from QI'ing to nsSimpleURI r=me
Attachment #535724 - Flags: review?(bzbarsky) → review+
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Whiteboard: fixed-in-cedar
As visible here [https://tbpl.mozilla.org/php/getParsedLog.php?id=6407277&full=1], the tests for this bug (test_bug660066.js and test_URIs.js) have passed.
Status: RESOLVED → VERIFIED
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: