Bug 1627673 - Do null-check the result of `DragEvent::GetDataTransfer()` in `EditorEventListener`` r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 09 Nov 2020 23:39:10 +0000
changeset 556486 5e40825560b7dccc8877c1ed6cadce3053b8f28d
parent 556485 98b994baee8826cf2129b4c49f4b39faa9b70e32
child 556487 4dd201db88c04fa3f254bc30b085f68567d1d460
push id37936
push usersmolnar@mozilla.com
push dateTue, 10 Nov 2020 09:57:49 +0000
treeherdermozilla-central@5942060b993b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1627673
milestone84.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 1627673 - Do null-check the result of `DragEvent::GetDataTransfer()` in `EditorEventListener`` r=smaug I guess that `DataTransfer::HasType()` is inlined in the opt builds and actually crashed in `EditorEventListener::DragEventHasSupportingData()` at accessing `aDragEvent->GetDataTransfer()` result without null-check because `DataTransfer::mItems` is set to `nullptr` only by the cycle collector, but it does not make sense to think that it occurs the STR in bug 1627673 comment 3. Therefore, this patch adds null-checks in `EditorEventListener::DragEventHasSupportingData()`. I have no idea how to test this with automated tests. Differential Revision: https://phabricator.services.mozilla.com/D96310
editor/libeditor/EditorEventListener.cpp
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -960,16 +960,20 @@ bool EditorEventListener::DragEventHasSu
     DragEvent* aDragEvent) const {
   MOZ_ASSERT(
       !DetachedFromEditorOrDefaultPrevented(aDragEvent->WidgetEventPtr()));
   MOZ_ASSERT(aDragEvent->GetDataTransfer());
 
   // Plaintext editors only support dropping text. Otherwise, HTML and files
   // can be dropped as well.
   DataTransfer* dataTransfer = aDragEvent->GetDataTransfer();
+  if (!dataTransfer) {
+    NS_WARNING("No data transfer returned");
+    return false;
+  }
   return dataTransfer->HasType(NS_LITERAL_STRING_FROM_CSTRING(kTextMime)) ||
          dataTransfer->HasType(
              NS_LITERAL_STRING_FROM_CSTRING(kMozTextInternal)) ||
          (!mEditorBase->IsPlaintextEditor() &&
           (dataTransfer->HasType(NS_LITERAL_STRING_FROM_CSTRING(kHTMLMime)) ||
            dataTransfer->HasType(NS_LITERAL_STRING_FROM_CSTRING(kFileMime))));
 }