From 94f2508519f7dd221b8db356c41e5f3c698f9774 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 17 Jan 2022 17:36:20 +0000 Subject: [PATCH] CrashReporter: Don't crash when investigating a HackStudio crash Previously when opening a crash report for HackStudio, the `unveil("/bin/HackStudio", "rx")` call was failing because of the earlier `unveil(executable_path.characters(), "r")` call requesting only "r" permissions for it. This patch handles this specific case, so you can crash HackStudio to your heart's content. :^) Also, we were unveiling the executable path twice, once manually and once implicitly as part of the coredump's libraries, so we now check for the latter and avoid it. Thanks to Daniel for noticing what was right in front of me and I didn't see! Co-authored-by: Daniel Bertalan --- Userland/Applications/CrashReporter/main.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Userland/Applications/CrashReporter/main.cpp b/Userland/Applications/CrashReporter/main.cpp index 89d73a87bc..f0fb94e2ef 100644 --- a/Userland/Applications/CrashReporter/main.cpp +++ b/Userland/Applications/CrashReporter/main.cpp @@ -165,14 +165,21 @@ ErrorOr serenity_main(Main::Arguments arguments) if (unlink_on_exit) TRY(Core::System::unveil(coredump_path, "c")); - TRY(Core::System::unveil(executable_path.characters(), "r")); - TRY(Core::System::unveil("/bin/HackStudio", "rx")); + + // If the executable is HackStudio, then the two unveil()s would conflict! + if (executable_path == "/bin/HackStudio") { + TRY(Core::System::unveil("/bin/HackStudio", "rx")); + } else { + TRY(Core::System::unveil(executable_path.characters(), "r")); + TRY(Core::System::unveil("/bin/HackStudio", "rx")); + } + TRY(Core::System::unveil("/res", "r")); TRY(Core::System::unveil("/tmp/portal/launch", "rw")); TRY(Core::System::unveil("/usr/lib", "r")); - coredump->for_each_library([](auto library_info) { + coredump->for_each_library([&executable_path](auto library_info) { // FIXME: Make for_each_library propagate ErrorOr values so we can use TRY. - if (library_info.path.starts_with('/')) + if (library_info.path.starts_with('/') && library_info.path != executable_path) MUST(Core::System::unveil(library_info.path, "r")); }); TRY(Core::System::unveil(nullptr, nullptr));