Skip to content

Commit

Permalink
fix call to system() when brackets present in path
Browse files Browse the repository at this point in the history
  • Loading branch information
wheybags committed Mar 6, 2020
1 parent c912d5b commit eaac98a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/freeablo/fa_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int fa_main(int argc, char** argv)
if (!(settings.loadUserSettings() && dataFilesSetUp(settings)))
{
filesystem::path path = (filesystem::path(argv[0]).parent_path() / "launcher").make_absolute();
system(Misc::escapeSpacesOnPath(path.str()).c_str());
system(Misc::escapePathForShell(path.str()).c_str());
return EXIT_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/launcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int main(int, char** argv)
if (runFreeablo)
{
filesystem::path path = (filesystem::path(argv[0]).parent_path() / "freeablo").make_absolute();
system(Misc::escapeSpacesOnPath(path.str()).c_str());
system(Misc::escapePathForShell(path.str()).c_str());
}

return 0;
Expand Down
13 changes: 6 additions & 7 deletions components/misc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,21 @@ namespace Misc
return ss.str() + suffix;
}

std::string escapeSpacesOnPath(const std::string& path)
std::string escapePathForShell(const std::string& path)
{
#ifdef _WIN32
return "\"" + path + "\"";
#else
std::stringstream ret;

ret << '"';
for (char c : path)
{
if (c == ' ')
ret << "\\ ";
if (c == '"')
ret << "\\\"";
else
ret << c;
}
ret << '"';

return ret.str();
#endif
}

std::string argv0;
Expand Down
2 changes: 1 addition & 1 deletion components/misc/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Misc

std::string numberToHumanFileSize(double sizeInBytes);

std::string escapeSpacesOnPath(const std::string& str);
std::string escapePathForShell(const std::string& str);
}

template <typename T> class NonNullPtr
Expand Down

0 comments on commit eaac98a

Please sign in to comment.