Commit 27714139 authored by Gilles Khouzam's avatar Gilles Khouzam Committed by Brad King
Browse files

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
parent dc3fdd7f
...@@ -4879,11 +4879,8 @@ std::string SystemTools::GetOperatingSystemNameAndVersion() ...@@ -4879,11 +4879,8 @@ std::string SystemTools::GetOperatingSystemNameAndVersion()
OSVERSIONINFOEXA osvi; OSVERSIONINFOEXA osvi;
BOOL bOsVersionInfoEx; BOOL bOsVersionInfoEx;
// Try calling GetVersionEx using the OSVERSIONINFOEX structure. ZeroMemory(&osvi, sizeof(osvi));
// If that fails, try using the OSVERSIONINFO structure. osvi.dwOSVersionInfoSize = sizeof(osvi);
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXA));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx #ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
# pragma warning (push) # pragma warning (push)
...@@ -4893,14 +4890,10 @@ std::string SystemTools::GetOperatingSystemNameAndVersion() ...@@ -4893,14 +4890,10 @@ std::string SystemTools::GetOperatingSystemNameAndVersion()
# pragma warning (disable:4996) # pragma warning (disable:4996)
# endif # endif
#endif #endif
bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi); bOsVersionInfoEx = GetVersionExA((OSVERSIONINFOA *)&osvi);
if (!bOsVersionInfoEx) if (!bOsVersionInfoEx)
{ {
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); return 0;
if (!GetVersionEx((OSVERSIONINFO *)&osvi))
{
return 0;
}
} }
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx #ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
# pragma warning (pop) # pragma warning (pop)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment