From f8cd9c7e55e46a7f957eb9d673f90b6d8013d2fd Mon Sep 17 00:00:00 2001 From: Akira Miyakoda Date: Thu, 18 Jan 2018 00:36:27 +0900 Subject: [PATCH] Windows: Use sufficient buffer for config file paths. MAX_PATH bytes are insufficient when a very long path is converted into UTF-8. --- Windows/main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Windows/main.cpp b/Windows/main.cpp index 8c10f1e99d..4d6a28c849 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -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 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;