From fec0829c86fb7d63cf54a52849b7f7bb4c0d20b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Eigm=C3=BCller?= Date: Fri, 7 Jan 2022 19:46:21 +0100 Subject: [PATCH] man: Fix error handling when section is specified Previously, man would only check if a path is not associated with a manpage when no section was specified via the command line. So `man gibberish` would fail with "no man page for gibberish", but `man 2 gibberish` would fail with a runtime error and still open a pipe to the pager leading to a nasty crash. Moving the check outside the "if (!section)" block fixes this. Also: if a section is specified, the error message now echoes it back (no manpage for foo in section bar). --- Userland/Utilities/man.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Userland/Utilities/man.cpp b/Userland/Utilities/man.cpp index 08128c27bf..abfbb9caf3 100644 --- a/Userland/Utilities/man.cpp +++ b/Userland/Utilities/man.cpp @@ -91,13 +91,15 @@ ErrorOr serenity_main(Main::Arguments arguments) break; } } - if (!section) { - warnln("No man page for {}", name); - exit(1); - } } - auto filename = make_path(section); + if (section == nullptr) { + warnln("No man page for {}", name); + exit(1); + } else if (access(filename.characters(), R_OK) != 0) { + warnln("No man page for {} in section {}", name, section); + exit(1); + } String pager_command; if (pager)