From da146bc5c1be4be9afb42a570a785f645c0b9edf Mon Sep 17 00:00:00 2001 From: ekoby <7406535+ekoby@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:15:18 -0400 Subject: [PATCH] do not rely on a hidden symbol from libuv --- library/posture.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/library/posture.c b/library/posture.c index 7c69f518..ac258d82 100644 --- a/library/posture.c +++ b/library/posture.c @@ -26,11 +26,9 @@ #pragma comment(lib, "netapi32.lib") #pragma comment(lib, "bcrypt.lib") +#include +#include -// provided by libuv -typedef NTSTATUS (NTAPI *sRtlGetVersion) - (PRTL_OSVERSIONINFOW lpVersionInformation); -extern sRtlGetVersion pRtlGetVersion; #elif __APPLE__ && __MACH__ #include @@ -668,19 +666,36 @@ static void ziti_pr_handle_process(ziti_context ztx, const char *id, const char ziti_collect_pr(ztx, path, obj, obj_len); } -static void default_pq_os(ziti_context ztx, const char *id, ziti_pr_os_cb response_cb) { +#if _WIN32 +typedef NTSTATUS (NTAPI *sRtlGetVersion) + (PRTL_OSVERSIONINFOW lpVersionInformation); + +static sRtlGetVersion get_win32_version_f() { + static sRtlGetVersion s_func; + if (s_func == NULL) { + HMODULE ntdll = GetModuleHandleA("ntdll.dll"); + s_func = (sRtlGetVersion) GetProcAddress(ntdll, "RtlGetVersion"); + } + return s_func; +} +static + +#endif // _WIN32 + +void default_pq_os(ziti_context ztx, const char *id, ziti_pr_os_cb response_cb) { const char *os; const char *ver; const char *build; #if _WIN32 OSVERSIONINFOEXW os_info = {0}; os_info.dwOSVersionInfoSize = sizeof(os_info); - if (pRtlGetVersion) { - pRtlGetVersion((PRTL_OSVERSIONINFOW) &os_info); + sRtlGetVersion version_f = get_win32_version_f(); + if (version_f) { + version_f((PRTL_OSVERSIONINFOW) &os_info); } else { /* Silence GetVersionEx() deprecation warning. */ #pragma warning(suppress : 4996) - GetVersionExW(&os_info); + GetVersionExW((LPOSVERSIONINFOW) &os_info); } switch (os_info.wProductType) {