Richard W.M. Jones
2022-Dec-01 11:20 UTC
[Libguestfs] [PATCH libguestfs 2/2] lib: Return correct osinfo field for Windows 11
On Thu, Dec 01, 2022 at 10:34:09AM +0000, Richard W.M. Jones wrote:> For Windows Client, we can only distinguish between Windows 10 and > Windows 11 using the build ID. The product name in both cases is > "Windows 10 <something>", apparently intentionally. > > References: > https://learn.microsoft.com/en-us/answers/questions/586619/windows-11-build-ver-is-still-10022000194.html > https://github.com/cygwin/cygwin/blob/a263fe0b268580273c1adc4b1bad256147990222/winsup/cygwin/wincap.cc#L429 > https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions > > After this fix, the output of virt-inspector changes to this, which is > a bit odd, but correct: > > <name>windows</name> > <arch>x86_64</arch> > <distro>windows</distro> > <product_name>Windows 10 Pro</product_name> > <product_variant>Client</product_variant> > <major_version>10</major_version> > <minor_version>0</minor_version> > <windows_systemroot>/Windows</windows_systemroot> > <windows_current_control_set>ControlSet001</windows_current_control_set> > <osinfo>win11</osinfo> > > Thanks: Yaakov Selkowitz > Reported-by: Yongkui Guo > Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2012658 > --- > lib/inspect-osinfo.c | 25 +++++++++++++++++++++++-- > 1 file changed, 23 insertions(+), 2 deletions(-) > > diff --git a/lib/inspect-osinfo.c b/lib/inspect-osinfo.c > index 90e57e6dfa..9a22a9d037 100644 > --- a/lib/inspect-osinfo.c > +++ b/lib/inspect-osinfo.c > @@ -86,6 +86,8 @@ guestfs_impl_inspect_get_osinfo (guestfs_h *g, const char *root) > else if (STREQ (type, "windows")) { > CLEANUP_FREE char *product_name = NULL; > CLEANUP_FREE char *product_variant = NULL; > + CLEANUP_FREE char *build_id_str = NULL; > + int build_id; > > product_name = guestfs_inspect_get_product_name (g, root); > if (!product_name) > @@ -142,8 +144,27 @@ guestfs_impl_inspect_get_osinfo (guestfs_h *g, const char *root) > return safe_strdup (g, "win2k19"); > else > return safe_strdup (g, "win2k16"); > - } else > - return safe_strdup (g, "win10"); > + } > + else { > + /* For Windows >= 10 Client we can only distinguish between > + * versions by looking at the build ID. See: > + * https://learn.microsoft.com/en-us/answers/questions/586619/windows-11-build-ver-is-still-10022000194.html > + * https://github.com/cygwin/cygwin/blob/a263fe0b268580273c1adc4b1bad256147990222/winsup/cygwin/wincap.cc#L429 > + */ > + build_id_str = guestfs_inspect_get_build_id (g, root); > + if (!build_id_str) > + return NULL; > + > + if (sscanf (build_id_str, "%d", &build_id) != 1) { > + error (g, "cannot parse Windows build ID from this guest"); > + return NULL; > + } > + > + if (build_id >= 2200)This should of course be 22000! Updated my copy. Rich.> + return safe_strdup (g, "win11"); > + else > + return safe_strdup (g, "win10"); > + } > } > break; > } > -- > 2.37.3 > > _______________________________________________ > Libguestfs mailing list > Libguestfs at redhat.com > https://listman.redhat.com/mailman/listinfo/libguestfs-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Laszlo Ersek
2022-Dec-02 09:11 UTC
[Libguestfs] [PATCH libguestfs 2/2] lib: Return correct osinfo field for Windows 11
On 12/01/22 12:20, Richard W.M. Jones wrote:> On Thu, Dec 01, 2022 at 10:34:09AM +0000, Richard W.M. Jones wrote: >> For Windows Client, we can only distinguish between Windows 10 and >> Windows 11 using the build ID. The product name in both cases is >> "Windows 10 <something>", apparently intentionally. >> >> References: >> https://learn.microsoft.com/en-us/answers/questions/586619/windows-11-build-ver-is-still-10022000194.html >> https://github.com/cygwin/cygwin/blob/a263fe0b268580273c1adc4b1bad256147990222/winsup/cygwin/wincap.cc#L429 >> https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions >> >> After this fix, the output of virt-inspector changes to this, which is >> a bit odd, but correct: >> >> <name>windows</name> >> <arch>x86_64</arch> >> <distro>windows</distro> >> <product_name>Windows 10 Pro</product_name> >> <product_variant>Client</product_variant> >> <major_version>10</major_version> >> <minor_version>0</minor_version> >> <windows_systemroot>/Windows</windows_systemroot> >> <windows_current_control_set>ControlSet001</windows_current_control_set> >> <osinfo>win11</osinfo> >> >> Thanks: Yaakov Selkowitz >> Reported-by: Yongkui Guo >> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2012658 >> --- >> lib/inspect-osinfo.c | 25 +++++++++++++++++++++++-- >> 1 file changed, 23 insertions(+), 2 deletions(-) >> >> diff --git a/lib/inspect-osinfo.c b/lib/inspect-osinfo.c >> index 90e57e6dfa..9a22a9d037 100644 >> --- a/lib/inspect-osinfo.c >> +++ b/lib/inspect-osinfo.c >> @@ -86,6 +86,8 @@ guestfs_impl_inspect_get_osinfo (guestfs_h *g, const char *root) >> else if (STREQ (type, "windows")) { >> CLEANUP_FREE char *product_name = NULL; >> CLEANUP_FREE char *product_variant = NULL; >> + CLEANUP_FREE char *build_id_str = NULL; >> + int build_id; >> >> product_name = guestfs_inspect_get_product_name (g, root); >> if (!product_name) >> @@ -142,8 +144,27 @@ guestfs_impl_inspect_get_osinfo (guestfs_h *g, const char *root) >> return safe_strdup (g, "win2k19"); >> else >> return safe_strdup (g, "win2k16"); >> - } else >> - return safe_strdup (g, "win10"); >> + } >> + else { >> + /* For Windows >= 10 Client we can only distinguish between >> + * versions by looking at the build ID. See: >> + * https://learn.microsoft.com/en-us/answers/questions/586619/windows-11-build-ver-is-still-10022000194.html >> + * https://github.com/cygwin/cygwin/blob/a263fe0b268580273c1adc4b1bad256147990222/winsup/cygwin/wincap.cc#L429 >> + */ >> + build_id_str = guestfs_inspect_get_build_id (g, root); >> + if (!build_id_str) >> + return NULL;Does this deserve an error() call like the one below?>> + >> + if (sscanf (build_id_str, "%d", &build_id) != 1) { >> + error (g, "cannot parse Windows build ID from this guest"); >> + return NULL; >> + } >> + >> + if (build_id >= 2200) > > This should of course be 22000! Updated my copy.In addition, please replace sscanf() with strtol(). The behavior of the former is undefined when the subject sequence forms a valid decimal string, but the numeric value does not fit into an "int". And, this is untrusted data. strtol() handles this securely (although strtol() is not trivial to use). I seem to remember gnulib offers xstrol() -- indeed, our trimmed, embedded copy of gnulib offers xstrtol(), from commit 0f54df53d26e ("build: Remove gnulib.", 2021-04-08); so that's the function to use here, IMO. series Reviewed-by: Laszlo Ersek <lersek at redhat.com>> > Rich. > >> + return safe_strdup (g, "win11"); >> + else >> + return safe_strdup (g, "win10"); >> + } >> } >> break; >> } >> -- >> 2.37.3 >> >> _______________________________________________ >> Libguestfs mailing list >> Libguestfs at redhat.com >> https://listman.redhat.com/mailman/listinfo/libguestfs >