Skip to content

Commit

Permalink
tweak: safer args bounds check + more explicit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ToeKneeRED committed Sep 9, 2024
1 parent 1bc1a1b commit 50488e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Code/immersive_launcher/Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ bool HandleArguments(int aArgc, char** aArgv, bool& aAskSelect)
aAskSelect = true;
else if (std::strcmp(aArgv[i], "--exePath") == 0)
{
if (!aArgv[i + 1])
if(i + 1 >= aArgc)
{
SetLastError(ERROR_BAD_PATHNAME);
Die(L"No exe path specified", true);
return false;
}

if (!oobe::PathArgument(aArgv[i + 1]))
{
SetLastError(ERROR_BAD_ARGUMENTS);
Die(L"Failed to parse path argument", true);
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion Code/immersive_launcher/oobe/PathArgument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,30 @@ bool ValidatePath(const std::wstring& acPath)

if (acPath.find_last_of('\\') == std::string::npos || acPath.ends_with(*"\\"))
{
SetLastError(ERROR_BAD_PATHNAME);
errorText += L"Invalid path\n";
}

if (!acPath.ends_with(L".exe"))
{
SetLastError(ERROR_BAD_ARGUMENTS);
errorText += acPath.substr(acPath.find_last_of('\\') + 1, acPath.back()) + L" is not an executable file\n";
}
else if (!acPath.ends_with(TARGET_NAME L".exe"))
{
SetLastError(ERROR_FILE_NOT_FOUND);
errorText += TARGET_NAME L".exe not found\n";
}

if (!std::filesystem::exists(g_exePath) || !std::filesystem::exists(g_titlePath))
{
SetLastError(ERROR_BAD_PATHNAME);
errorText += L"Path does not exist\n";
}

if (!errorText.empty())
{
errorText += L"Path: " + acPath;
errorText += L"\nPath: " + acPath;
DIE_NOW(errorText.c_str())
}

Expand Down

0 comments on commit 50488e3

Please sign in to comment.