LibWeb: Prevent crash when editing outside of <body>

Step 9 of this algorithm might end up at the document node, which does
not have a parent.
This commit is contained in:
Jelle Raaijmakers 2024-12-02 16:40:44 +01:00 committed by Andreas Kling
parent 6804ce348e
commit 90d884a150
Notes: github-actions[bot] 2024-12-04 16:18:47 +00:00

View file

@ -203,6 +203,11 @@ bool command_delete_action(DOM::Document& document, String const&)
// 9. Repeat the following steps:
while (true) {
// AD-HOC: If start node is not a Node, return false. This prevents a crash by dereferencing a null pointer in
// step 1 below. Edits outside of <body> might be prohibited: https://github.com/w3c/editing/issues/405
if (!start_node)
return false;
// 1. If start offset is zero, set start offset to the index of start node and then set
// start node to its parent.
if (start_offset == 0) {