1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

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).
This commit is contained in:
Julian Eigmüller 2022-01-07 19:46:21 +01:00 committed by Linus Groh
parent 2aff8b4a27
commit fec0829c86

View file

@ -91,13 +91,15 @@ ErrorOr<int> 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)