From ca29fc690ad38702056c79bec550612e0564d2df Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Sat, 21 Jan 2023 14:01:43 -0500 Subject: [PATCH] Have fallback in case GetProcAddress fails --- cups/usersys.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cups/usersys.c b/cups/usersys.c index 21352bbe46..977f6ef80b 100644 --- a/cups/usersys.c +++ b/cups/usersys.c @@ -548,7 +548,7 @@ cupsSetUserAgent(const char *user_agent)/* I - User-Agent string or @code NULL@ /* Thread globals */ #ifdef _WIN32 SYSTEM_INFO sysinfo; /* System information */ - OSVERSIONINFOA version; /* OS version info */ + OSVERSIONINFOW version; /* OS version info */ const char *machine; /* Hardware/machine name */ #elif defined(__APPLE__) struct utsname name; /* uname info */ @@ -595,15 +595,19 @@ cupsSetUserAgent(const char *user_agent)/* I - User-Agent string or @code NULL@ typedef NTSTATUS(WINAPI * RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); + memset(&version, 0, sizeof(version)) + version.dwOSVersionInfoSize = sizeof(version); + + /* RtlGetVersion gets the current native version of Windows, even when running in compatibility mode */ RtlGetVersionPtr RtlGetVersionInternal = (RtlGetVersionPtr)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"); if (RtlGetVersionInternal) { - version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); RtlGetVersionInternal((PRTL_OSVERSIONINFOW)&version); } else { - ZeroMemory(&version, sizeof(version)); + /* Should not happen, but just in case, fallback to deprecated GetVersionExW */ + GetVersionExW(&version); } GetNativeSystemInfo(&sysinfo); -- 2.47.2