Fix potential buffer overflows

This commit is contained in:
Ben Payne 2014-12-11 20:07:11 -05:00
parent cadc390895
commit 8d4679b2b7

View file

@ -75,10 +75,11 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdL
return -1; return -1;
} }
enum { errorSize = 4096 };
if (!hGame) if (!hGame)
{ {
wchar_t error[4096]; wchar_t error[errorSize];
_swprintf_l(error, sizeof(error), L"Unable to load game library: %s. Please make sure it exists and the latest DirectX is installed.", _get_current_locale(), dllName.c_str()); _swprintf_l(error, errorSize, L"Unable to load game library: %s. Please make sure it exists and the latest DirectX is installed.", _get_current_locale(), dllName.c_str());
MessageBoxW(NULL, error, L"Error", MB_OK|MB_ICONWARNING); MessageBoxW(NULL, error, L"Error", MB_OK|MB_ICONWARNING);
return -1; return -1;
} }
@ -86,8 +87,8 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdL
torque_winmain = (int (*)(HINSTANCE hInstance, HINSTANCE h, LPSTR lpszCmdLine, int nShow))GetProcAddress(hGame, "torque_winmain"); torque_winmain = (int (*)(HINSTANCE hInstance, HINSTANCE h, LPSTR lpszCmdLine, int nShow))GetProcAddress(hGame, "torque_winmain");
if (!torque_winmain) if (!torque_winmain)
{ {
wchar_t error[4096]; wchar_t error[errorSize];
_swprintf_l(error, sizeof(error), L"Missing torque_winmain export in game library: %s. Please make sure that it exists and the latest DirectX is installed.", _get_current_locale(), dllName.c_str()); _swprintf_l(error, errorSize, L"Missing torque_winmain export in game library: %s. Please make sure that it exists and the latest DirectX is installed.", _get_current_locale(), dllName.c_str());
MessageBoxW(NULL, error, L"Error", MB_OK|MB_ICONWARNING); MessageBoxW(NULL, error, L"Error", MB_OK|MB_ICONWARNING);
return -1; return -1;
} }