diff mbox series

[3/5] qga/commands-win32: Use os_get_win_version()

Message ID 20220727073542.811420-4-bmeng.cn@gmail.com
State Superseded
Headers show
Series Enable unix socket support on Windows | expand

Commit Message

Bin Meng July 27, 2022, 7:35 a.m. UTC
From: Bin Meng <bin.meng@windriver.com>

Drop its own ga_get_win_version() implementation, and use the one
provided in oslib-win32 instead.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 qga/commands-win32.c | 27 +--------------------------
 1 file changed, 1 insertion(+), 26 deletions(-)

Comments

Konstantin Kostiuk July 27, 2022, 8:59 a.m. UTC | #1
On Wed, Jul 27, 2022 at 10:36 AM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Drop its own ga_get_win_version() implementation, and use the one
> provided in oslib-win32 instead.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  qga/commands-win32.c | 27 +--------------------------
>  1 file changed, 1 insertion(+), 26 deletions(-)
>
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 7ed7664715..6186f2e1f2 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -2178,26 +2178,6 @@ static ga_win_10_0_t const
> WIN_10_0_CLIENT_VERSION_MATRIX[3] = {
>      {0, 0}
>  };
>
> -static void ga_get_win_version(RTL_OSVERSIONINFOEXW *info, Error **errp)
> -{
> -    typedef NTSTATUS(WINAPI *rtl_get_version_t)(
> -        RTL_OSVERSIONINFOEXW *os_version_info_ex);
> -
> -    info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
> -
> -    HMODULE module = GetModuleHandle("ntdll");
> -    PVOID fun = GetProcAddress(module, "RtlGetVersion");
> -    if (fun == NULL) {
> -        error_setg(errp, QERR_QGA_COMMAND_FAILED,
> -            "Failed to get address of RtlGetVersion");
> -        return;
> -    }
> -
> -    rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
> -    rtl_get_version(info);
> -    return;
> -}
> -
>  static char *ga_get_win_name(OSVERSIONINFOEXW const *os_version, bool id)
>  {
>      DWORD major = os_version->dwMajorVersion;
> @@ -2312,17 +2292,12 @@ static char *ga_get_current_arch(void)
>
>  GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
>  {
> -    Error *local_err = NULL;
>      OSVERSIONINFOEXW os_version = {0};
>      bool server;
>      char *product_name;
>      GuestOSInfo *info;
>
> -    ga_get_win_version(&os_version, &local_err);
> -    if (local_err) {
> -        error_propagate(errp, local_err);
> -        return NULL;
> -    }
> +    os_get_win_version(&os_version);
>

GA should not fail if it can't detect the Windows version but theoretically
os_get_win_version can crash application if GetProcAddress will return NULL


>
>      server = os_version.wProductType != VER_NT_WORKSTATION;
>      product_name = ga_get_win_product_name(errp);
> --
> 2.34.1
>
>
diff mbox series

Patch

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 7ed7664715..6186f2e1f2 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -2178,26 +2178,6 @@  static ga_win_10_0_t const WIN_10_0_CLIENT_VERSION_MATRIX[3] = {
     {0, 0}
 };
 
-static void ga_get_win_version(RTL_OSVERSIONINFOEXW *info, Error **errp)
-{
-    typedef NTSTATUS(WINAPI *rtl_get_version_t)(
-        RTL_OSVERSIONINFOEXW *os_version_info_ex);
-
-    info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
-
-    HMODULE module = GetModuleHandle("ntdll");
-    PVOID fun = GetProcAddress(module, "RtlGetVersion");
-    if (fun == NULL) {
-        error_setg(errp, QERR_QGA_COMMAND_FAILED,
-            "Failed to get address of RtlGetVersion");
-        return;
-    }
-
-    rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
-    rtl_get_version(info);
-    return;
-}
-
 static char *ga_get_win_name(OSVERSIONINFOEXW const *os_version, bool id)
 {
     DWORD major = os_version->dwMajorVersion;
@@ -2312,17 +2292,12 @@  static char *ga_get_current_arch(void)
 
 GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
 {
-    Error *local_err = NULL;
     OSVERSIONINFOEXW os_version = {0};
     bool server;
     char *product_name;
     GuestOSInfo *info;
 
-    ga_get_win_version(&os_version, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return NULL;
-    }
+    os_get_win_version(&os_version);
 
     server = os_version.wProductType != VER_NT_WORKSTATION;
     product_name = ga_get_win_product_name(errp);