From 27714139e04165a1d51b1cfe11ab56c1b96e328a Mon Sep 17 00:00:00 2001 From: Gilles Khouzam <gillesk@microsoft.com> Date: Thu, 10 Sep 2015 13:53:00 -0700 Subject: [PATCH] SystemTools: Call GetVersionEx more robustly We pass a OSVERSIONINFOEXA structure so call GetVersionExA explicitly to avoid ever calling GetVersionExW with a structure of the wrong size by mistake. Change-Id: I892ae0497ef3ca4b38cd2c1c1870d165b0bd8713 --- SystemTools.cxx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/SystemTools.cxx b/SystemTools.cxx index 97a1df8..ddf42b6 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -4879,11 +4879,8 @@ std::string SystemTools::GetOperatingSystemNameAndVersion() OSVERSIONINFOEXA osvi; BOOL bOsVersionInfoEx; - // Try calling GetVersionEx using the OSVERSIONINFOEX structure. - // If that fails, try using the OSVERSIONINFO structure. - - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXA)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); + ZeroMemory(&osvi, sizeof(osvi)); + osvi.dwOSVersionInfoSize = sizeof(osvi); #ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx # pragma warning (push) @@ -4893,14 +4890,10 @@ std::string SystemTools::GetOperatingSystemNameAndVersion() # pragma warning (disable:4996) # endif #endif - bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi); + bOsVersionInfoEx = GetVersionExA((OSVERSIONINFOA *)&osvi); if (!bOsVersionInfoEx) { - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if (!GetVersionEx((OSVERSIONINFO *)&osvi)) - { - return 0; - } + return 0; } #ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx # pragma warning (pop) -- GitLab