Skip to content

Commit

Permalink
LibWeb: Prevent crash when editing outside of <body>
Browse files Browse the repository at this point in the history
Step 9 of this algorithm might end up at the document node, which does
not have a parent.
  • Loading branch information
gmta committed Dec 2, 2024
1 parent 1b3f8e1 commit d3e4ccc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Libraries/LibWeb/Editing/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,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) {
Expand Down

0 comments on commit d3e4ccc

Please sign in to comment.