From 79f6246f12e679ffb4a83fddfacd4dbd2ef83549 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Fri, 16 Apr 2010 21:45:13 +0300 Subject: [PATCH] Bug 559526 - Moving a NodeIterator from its NodeFilter causes a crash, r=sicking --HG-- extra : rebase_source : fc22f797ae28009752075c21a280647f042c886c --- content/base/src/nsNodeIterator.cpp | 2 +- content/base/src/nsTraversal.cpp | 10 ++- content/base/src/nsTraversal.h | 3 +- content/base/test/Makefile.in | 1 + content/base/test/test_bug559526.html | 97 +++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 content/base/test/test_bug559526.html diff --git a/content/base/src/nsNodeIterator.cpp b/content/base/src/nsNodeIterator.cpp index 091581e7d3e..ec39736bdc6 100644 --- a/content/base/src/nsNodeIterator.cpp +++ b/content/base/src/nsNodeIterator.cpp @@ -301,7 +301,7 @@ nsNodeIterator::NextOrPrevNode(NodePointer::MoveToMethodType aMove, *_retval = nsnull; - if (mDetached) + if (mDetached || mInAcceptNode) return NS_ERROR_DOM_INVALID_STATE_ERR; mWorkingPointer = mPointer; diff --git a/content/base/src/nsTraversal.cpp b/content/base/src/nsTraversal.cpp index 9d835ca6eb1..3029096f4e2 100644 --- a/content/base/src/nsTraversal.cpp +++ b/content/base/src/nsTraversal.cpp @@ -54,7 +54,8 @@ nsTraversal::nsTraversal(nsINode *aRoot, mRoot(aRoot), mWhatToShow(aWhatToShow), mFilter(aFilter), - mExpandEntityReferences(aExpandEntityReferences) + mExpandEntityReferences(aExpandEntityReferences), + mInAcceptNode(PR_FALSE) { NS_ASSERTION(aRoot, "invalid root in call to nsTraversal constructor"); } @@ -73,6 +74,8 @@ nsTraversal::~nsTraversal() */ nsresult nsTraversal::TestNode(nsINode* aNode, PRInt16* _filtered) { + NS_ENSURE_TRUE(!mInAcceptNode, NS_ERROR_DOM_INVALID_STATE_ERR); + nsresult rv; *_filtered = nsIDOMNodeFilter::FILTER_SKIP; @@ -114,7 +117,10 @@ nsresult nsTraversal::TestNode(nsINode* aNode, PRInt16* _filtered) domNode = do_QueryInterface(aNode); } - return mFilter->AcceptNode(domNode, _filtered); + mInAcceptNode = PR_TRUE; + rv = mFilter->AcceptNode(domNode, _filtered); + mInAcceptNode = PR_FALSE; + return rv; } *_filtered = nsIDOMNodeFilter::FILTER_ACCEPT; diff --git a/content/base/src/nsTraversal.h b/content/base/src/nsTraversal.h index 37dae6e45d3..b7f67269135 100644 --- a/content/base/src/nsTraversal.h +++ b/content/base/src/nsTraversal.h @@ -62,7 +62,8 @@ protected: nsCOMPtr mRoot; PRUint32 mWhatToShow; nsCOMPtr mFilter; - PRBool mExpandEntityReferences; + PRPackedBool mExpandEntityReferences; + PRPackedBool mInAcceptNode; /* * Tests if and how a node should be filtered. Uses mWhatToShow and diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index f9d6e0fef85..3e47632c0b0 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -372,6 +372,7 @@ _TEST_FILES = test_bug5141.html \ test_bug558726.html \ test_bug557892.html \ file_bug557892.html \ + test_bug559526.html \ $(NULL) # This test fails on the Mac for some reason diff --git a/content/base/test/test_bug559526.html b/content/base/test/test_bug559526.html new file mode 100644 index 00000000000..3abb8f76039 --- /dev/null +++ b/content/base/test/test_bug559526.html @@ -0,0 +1,97 @@ + + + + + Test for Bug 559526 + + + + + +Mozilla Bug 559526 +

+ +
+
+
+
+ +