From 135c21a687995f6d4496b0cf5a2bb95e32f1311f Mon Sep 17 00:00:00 2001 From: shiro <18399-shiro@users.noreply.gitgud.io> Date: Sun, 25 Sep 2022 00:08:58 +0000 Subject: [PATCH] Prevent crash constructing string from nulltpr If XDG_CURRENT_DESKTOP isn't set, getenv returns a `nullptr`. Constructing a `std::string` from `nullptr` will throw an exception. This prevents a crash when not using a DE, but zenity or kdialog is installed regardless (also fixes a typo where the fallthrough attribute wasn't applied to anything due to a missing semicolon) --- FCHost/fchost/fchost_handler_linux.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FCHost/fchost/fchost_handler_linux.cc b/FCHost/fchost/fchost_handler_linux.cc index f960f287892..d78e9f63c1c 100644 --- a/FCHost/fchost/fchost_handler_linux.cc +++ b/FCHost/fchost/fchost_handler_linux.cc @@ -70,7 +70,7 @@ namespace { switch (mode) { case CefDialogHandler::FileDialogMode::FILE_DIALOG_OPEN_MULTIPLE: - cmdLine << " --multiple"; [[fallthrough]] + cmdLine << " --multiple"; [[fallthrough]]; case CefDialogHandler::FileDialogMode::FILE_DIALOG_OPEN: cmdLine << " --getopenfilename"; break; @@ -171,7 +171,8 @@ namespace { // we will try to launch kdialog or zenity std::string dialogExecutable; // try to determine which environment we run inside - std::string desktop = getenv("XDG_CURRENT_DESKTOP"); + const char* desktop_env = getenv("XDG_CURRENT_DESKTOP"); + std::string desktop = desktop_env == nullptr ? "" : desktop_env; const auto checkExeExists = [](const char* name) { int ec = ::system((std::string(name) + " --help > /dev/null").c_str()); -- GitLab