[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] inspection: Fix detection of the kernel version of Windows ≥ 10 (RHBZ#12 81578).



See the description in the bug report:

https://bugzilla.redhat.com/show_bug.cgi?id=1281578

Thanks: Richard Tollerton for alerting me to this change in the way
that Windows version numbers are stored in the Registry starting with
Windows ≥ 10.
---
 src/inspect-fs-windows.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index af28bb7..23b95fb 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
@@ -279,6 +280,7 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
     { "Microsoft", "Windows NT", "CurrentVersion" };
   size_t i;
   CLEANUP_FREE_HIVEX_VALUE_LIST struct guestfs_hivex_value_list *values = NULL;
+  bool ignore_currentversion = false;
 
   if (guestfs_hivex_open (g, software_path,
                           GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1)
@@ -309,7 +311,43 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
       if (!fs->product_name)
         goto out;
     }
-    else if (STRCASEEQ (key, "CurrentVersion")) {
+    else if (STRCASEEQ (key, "CurrentMajorVersionNumber")) {
+      size_t size;
+      int64_t type = guestfs_hivex_value_type (g, value);
+      CLEANUP_FREE char *buf = guestfs_hivex_value_value (g, value, &size);
+
+      if (buf == NULL)
+        goto out;
+      if (type != 4 || len != 4) {
+        error (g, "hivex: expected CurrentVersion\\%s to be a DWORD field",
+               "CurrentMajorVersionNumber");
+        goto out;
+      }
+
+      fs->major_version = le32toh (*(int32_t *)buf);
+
+      /* Ignore CurrentVersion if we see it after this key. */
+      ignore_currentversion = true;
+    }
+    else if (STRCASEEQ (key, "CurrentMinorVersionNumber")) {
+      size_t size;
+      int64_t type = guestfs_hivex_value_type (g, value);
+      CLEANUP_FREE char *buf = guestfs_hivex_value_value (g, value, &size);
+
+      if (buf == NULL)
+        goto out;
+      if (type != 4 || len != 4) {
+        error (g, "hivex: expected CurrentVersion\\%s to be a DWORD field",
+               "CurrentMinorVersionNumber");
+        goto out;
+      }
+
+      fs->minor_version = le32toh (*(int32_t *)buf);
+
+      /* Ignore CurrentVersion if we see it after this key. */
+      ignore_currentversion = true;
+    }
+    else if (!ignore_currentversion && STRCASEEQ (key, "CurrentVersion")) {
       CLEANUP_FREE char *version = guestfs_hivex_value_utf8 (g, value);
       if (!version)
         goto out;
-- 
2.5.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]