Bug 1425091 - Part 4. EditorBase::MoveNode should check valid node that has parent node. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 15 Dec 2017 10:56:45 -0600
changeset 714518 b5f49cebfedfd36cea42fc40cef42c48d9d4683a
parent 714517 ec2af4fdeae48c040bdf682b14c16600b2960186
child 744603 8e5f04a1e4772bedccb614a13ab86cc58e24e854
push id93936
push userbmo:m_kato@ga2.so-net.ne.jp
push dateSat, 23 Dec 2017 22:43:42 +0000
reviewersmasayuki
bugs1425091
milestone59.0a1
Bug 1425091 - Part 4. EditorBase::MoveNode should check valid node that has parent node. r?masayuki AutoMoveNodeSelNotify doesn't allow container is null. So we should reject that parent of moving node is null. MozReview-Commit-ID: DGNCicLJxuK
editor/libeditor/EditorBase.cpp
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1891,17 +1891,20 @@ EditorBase::MoveNode(nsIContent* aNode,
 {
   MOZ_ASSERT(aNode);
   MOZ_ASSERT(aParent);
   MOZ_ASSERT(aOffset == -1 ||
              (0 <= aOffset &&
               AssertedCast<uint32_t>(aOffset) <= aParent->Length()));
 
   nsCOMPtr<nsINode> oldParent = aNode->GetParentNode();
-  int32_t oldOffset = oldParent ? oldParent->IndexOf(aNode) : -1;
+  if (NS_WARN_IF(!oldParent)) {
+    return NS_ERROR_FAILURE;
+  }
+  int32_t oldOffset = oldParent->IndexOf(aNode);
 
   if (aOffset == -1) {
     // Magic value meaning "move to end of aParent"
     aOffset = AssertedCast<int32_t>(aParent->Length());
   }
 
   // Don't do anything if it's already in right place
   if (aParent == oldParent && aOffset == oldOffset) {