Przeglądaj źródła

Do not allow focusing into an unloaded document

This could result in a dangling pointer to the document in the document focus history. This would further lead to a crash under certain circumstances, when the destroyed document was accessed from the focus history, see #730.
Michael Ragazzon 8 miesięcy temu
rodzic
commit
a9a399475f
1 zmienionych plików z 7 dodań i 0 usunięć
  1. 7 0
      Source/Core/Context.cpp

+ 7 - 0
Source/Core/Context.cpp

@@ -993,6 +993,13 @@ bool Context::OnFocusChange(Element* new_focus, bool focus_visible)
 	if (old_document && old_document->IsModal() && (!new_document || !(new_document->IsModal() || new_document->IsFocusableFromModal())))
 		return false;
 
+	// If the document of the new focus has been closed, deny the request.
+	if (std::find_if(unloaded_documents.begin(), unloaded_documents.end(),
+			[&](const auto& unloaded_document) { return unloaded_document.get() == new_document; }) != unloaded_documents.end())
+	{
+		return false;
+	}
+
 	// Build the old chains
 	Element* element = old_focus;
 	while (element)