Windows: Use sufficient buffer for config file paths.

MAX_PATH bytes are insufficient when a very long path is converted into UTF-8.
This commit is contained in:
Akira Miyakoda 2018-01-18 00:36:27 +09:00
parent ec817df8d5
commit f8cd9c7e55

View file

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