Merge pull request #10538 from AkiraMiyakoda/fix-short-path-buffer

Windows: Use sufficient buffer for config file paths.
This commit is contained in:
Henrik Rydgård 2018-01-17 17:15:48 +01:00 committed by GitHub
commit b6ce6e2e6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -391,10 +391,10 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
langRegion = GetDefaultLangRegion();
osName = GetWindowsVersion() + " " + GetWindowsSystemArchitecture();
char configFilename[MAX_PATH] = { 0 };
std::string configFilename = "";
const std::wstring configOption = L"--config=";
char controlsConfigFilename[MAX_PATH] = { 0 };
std::string controlsConfigFilename = "";
const std::wstring controlsOption = L"--controlconfig=";
std::vector<std::wstring> wideArgs = GetWideCmdLine();
@ -405,14 +405,12 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
if (wideArgs[i][0] == L'-') {
if (wideArgs[i].find(configOption) != std::wstring::npos && wideArgs[i].size() > configOption.size()) {
const std::wstring tempWide = wideArgs[i].substr(configOption.size());
const std::string tempStr = ConvertWStringToUTF8(tempWide);
std::strncpy(configFilename, tempStr.c_str(), MAX_PATH);
configFilename = ConvertWStringToUTF8(tempWide);
}
if (wideArgs[i].find(controlsOption) != std::wstring::npos && wideArgs[i].size() > controlsOption.size()) {
const std::wstring tempWide = wideArgs[i].substr(controlsOption.size());
const std::string tempStr = ConvertWStringToUTF8(tempWide);
std::strncpy(controlsConfigFilename, tempStr.c_str(), MAX_PATH);
controlsConfigFilename = ConvertWStringToUTF8(tempWide);
}
}
}
@ -428,7 +426,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
g_Config.AddSearchPath("");
g_Config.AddSearchPath(GetSysDirectory(DIRECTORY_SYSTEM));
g_Config.SetDefaultPath(GetSysDirectory(DIRECTORY_SYSTEM));
g_Config.Load(configFilename, controlsConfigFilename);
g_Config.Load(configFilename.c_str(), controlsConfigFilename.c_str());
bool debugLogLevel = false;