Bug 1458016: Fix bad cast to Text. r=bz
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 30 Apr 2018 22:03:33 +0200
changeset 472476 4c0f3401afe5bcaf18f71d17e25f3719d8fdfd00
parent 472475 e4216d8898360c2e573bd412e966b956462338d6
child 472477 6f975a367b79036dc280c04677b33678aec38af0
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1458016
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1458016: Fix bad cast to Text. r=bz I think it's harmless security-wise, since Text and char data are both nsIContent, so the vtable offset should be the same. I could also just do AsContent(), which may be cleaner but involve a virtual call, or add AsCharacterData(), just let me know. MozReview-Commit-ID: 79I9CuCmioF
dom/base/Selection.cpp
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -3210,19 +3210,19 @@ Selection::ContainsNode(nsINode& aNode, 
 {
   nsresult rv;
   if (mRanges.Length() == 0) {
     return false;
   }
 
   // XXXbz this duplicates the GetNodeLength code in nsRange.cpp
   uint32_t nodeLength;
-  bool isData = aNode.IsCharacterData();
-  if (isData) {
-    nodeLength = aNode.AsText()->TextLength();
+  auto* nodeAsCharData = CharacterData::FromNode(aNode);
+  if (nodeAsCharData) {
+    nodeLength = nodeAsCharData->TextLength();
   } else {
     nodeLength = aNode.GetChildCount();
   }
 
   nsTArray<nsRange*> overlappingRanges;
   rv = GetRangesForIntervalArray(&aNode, 0, &aNode, nodeLength,
                                  false, &overlappingRanges);
   if (NS_FAILED(rv)) {
@@ -3233,17 +3233,17 @@ Selection::ContainsNode(nsINode& aNode, 
     return false; // no ranges overlap
 
   // if the caller said partial intersections are OK, we're done
   if (aAllowPartial) {
     return true;
   }
 
   // text nodes always count as inside
-  if (isData) {
+  if (nodeAsCharData) {
     return true;
   }
 
   // The caller wants to know if the node is entirely within the given range,
   // so we have to check all intersecting ranges.
   for (uint32_t i = 0; i < overlappingRanges.Length(); i++) {
     bool nodeStartsBeforeRange, nodeEndsAfterRange;
     if (NS_SUCCEEDED(nsRange::CompareNodeToRange(&aNode, overlappingRanges[i],