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
This commit is contained in:
Masayuki Nakano 2020-11-09 23:39:10 +00:00
parent 2d9159f48c
commit 00b602a0f0

View File

@ -965,6 +965,10 @@ bool EditorEventListener::DragEventHasSupportingData(
// 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)) ||