From 6ab13489eed93f75643caa9c986ef44078a46f48 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 25 Apr 2023 17:34:08 +0100 Subject: [PATCH] LibManual: Ensure page exists when opening a help URL Previously, Help could crash when attempting to open a help URL for a page that doesn't exist. --- Userland/Libraries/LibManual/Node.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibManual/Node.cpp b/Userland/Libraries/LibManual/Node.cpp index e54fcc8595..dc6871d07f 100644 --- a/Userland/Libraries/LibManual/Node.cpp +++ b/Userland/Libraries/LibManual/Node.cpp @@ -89,17 +89,25 @@ ErrorOr> Node::try_find_from_help_url(URL const& url) return Error::from_string_view("Section number out of bounds"sv); NonnullRefPtr current_node = sections[section_number - 1]; - + bool child_node_found; for (size_t i = 1; i < url.path_segment_count(); i++) { + child_node_found = false; auto children = TRY(current_node->children()); for (auto const& child : children) { if (TRY(child->name()) == url.path_segment_at_index(i).view()) { + child_node_found = true; current_node = child; break; } } + + if (!child_node_found) + break; } + if (!child_node_found) + return Error::from_string_view("Page not found"sv); + return current_node; }