From 4f9aefadefc906f401f69229dd89e3434c73806e Mon Sep 17 00:00:00 2001 From: Dana Burkart Date: Fri, 15 Oct 2021 13:51:43 -0700 Subject: [PATCH] LibWeb: Ensure parent is not null in DOMTreeModel::index_for_node() Fix a crash when inspecting empty pages or areas of the page with no elements. --- Userland/Libraries/LibWeb/DOMTreeModel.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOMTreeModel.cpp b/Userland/Libraries/LibWeb/DOMTreeModel.cpp index fda2f593b5..073d5e8ca3 100644 --- a/Userland/Libraries/LibWeb/DOMTreeModel.cpp +++ b/Userland/Libraries/LibWeb/DOMTreeModel.cpp @@ -172,6 +172,8 @@ GUI::ModelIndex DOMTreeModel::index_for_node(i32 node_id) const auto node = m_node_id_to_dom_node_map.get(node_id).value_or(nullptr); if (node) { auto* parent = get_parent(*node); + if (!parent) + return {}; auto parent_children = get_children(*parent); for (size_t i = 0; i < parent_children->size(); i++) { if (&parent_children->at(i).as_object() == node) {