From 093cbcd6063ec70c82e47e09a8c9d5ea95c1dffb Mon Sep 17 00:00:00 2001 From: Carwyn Nelson Date: Mon, 3 Jul 2023 21:02:49 +0100 Subject: [PATCH] LibManual: Error on section_number 0 instead of crashing Prior to this commit if you tried to access section 0 of the man page (`man 0 ls`) the application would just crash with an array out of bounds style error. This commit just ensures that we return an explicit and helpful error message when you try to request the 0th section, instead of crashing. --- Userland/Libraries/LibManual/SectionNode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibManual/SectionNode.cpp b/Userland/Libraries/LibManual/SectionNode.cpp index cc2a39f07a..d033235ebb 100644 --- a/Userland/Libraries/LibManual/SectionNode.cpp +++ b/Userland/Libraries/LibManual/SectionNode.cpp @@ -22,8 +22,8 @@ ErrorOr> SectionNode::try_create_from_number(StringVi if (!maybe_section_number.has_value()) return Error::from_string_literal("Section is not a number"); auto section_number = maybe_section_number.release_value(); - if (section_number > number_of_sections) - return Error::from_string_literal("Section number too large"); + if (section_number < 1 || section_number > number_of_sections) + return Error::from_string_literal("Section number is not valid"); return sections[section_number - 1]; }