Bug 592829: Don't crash if we fail to create an element during XML parsing. r=jst a=beta7blocker

This commit is contained in:
Jonas Sicking 2010-09-22 14:51:46 -07:00
parent 724cee7af2
commit 446e859c8d
4 changed files with 53 additions and 8 deletions

View File

@ -260,6 +260,7 @@ _TEST_FILES1 = test_bug5141.html \
test_bug505783.html \
test_bug457746.html \
test_bug587931.html \
test_bug592829.html \
test_bug518104.html \
bug457746.sjs \
test_CrossSiteXHR.html \

View File

@ -0,0 +1,42 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=592829
-->
<head>
<title>Test for Bug 592829</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=592829">Mozilla Bug 592829</a>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 592829 **/
// NOTE! It's imperative that we don't call .init() here. Otherwise we're not
// testing what happens if parsing fails.
// If we ever change how DOMParser initilization works, just update this code
// to create a DOMParser which is not allowed to parse XUL.
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var isXUL = true;
try {
var x =
Components.classes["@mozilla.org/xmlextras/domparser;1"]
.getService(Components.interfaces.nsIDOMParser)
.parseFromString('<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>', "text/xml");
isXUL = x.documentElement.namespaceURI ==
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
}
catch (ex) {
isXUL = false;
}
is(isXUL, false, "We didn't create XUL and we didn't crash!");
</script>
</pre>
</body>
</html>

View File

@ -871,15 +871,14 @@ nsXMLContentSink::GetCurrentContent()
if (mContentStack.Length() == 0) {
return nsnull;
}
return GetCurrentStackNode().mContent;
return GetCurrentStackNode()->mContent;
}
StackNode &
StackNode*
nsXMLContentSink::GetCurrentStackNode()
{
PRInt32 count = mContentStack.Length();
NS_ASSERTION(count > 0, "Bogus Length()");
return mContentStack[count-1];
return count != 0 ? &mContentStack[count-1] : nsnull;
}
@ -1116,11 +1115,14 @@ nsXMLContentSink::HandleEndElement(const PRUnichar *aName,
FlushText();
StackNode & sn = GetCurrentStackNode();
StackNode* sn = GetCurrentStackNode();
if (!sn) {
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIContent> content;
sn.mContent.swap(content);
PRUint32 numFlushed = sn.mNumFlushed;
sn->mContent.swap(content);
PRUint32 numFlushed = sn->mNumFlushed;
PopContent();
NS_ASSERTION(content, "failed to pop content");

View File

@ -148,7 +148,7 @@ protected:
nsresult AddContentAsLeaf(nsIContent *aContent);
nsIContent* GetCurrentContent();
StackNode & GetCurrentStackNode();
StackNode* GetCurrentStackNode();
nsresult PushContent(nsIContent *aContent);
void PopContent();
PRBool HaveNotifiedForCurrentContent() const;