Skip to content
Snippets Groups Projects
Commit 135c21a6 authored by shiro's avatar shiro :white_flower:
Browse files

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)
parent 955f0e76
No related branches found
No related tags found
1 merge request!11101[FCHost][Linux] Prevent crash constructing string from nulltpr
......@@ -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());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment