From 1c334e8e2becd50610657f7fd3dbe2e57b27480e Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Tue, 12 Mar 2024 15:11:36 -0700 Subject: [PATCH] WSL-Helper: Fix getting MSI version When getting the MSI version, we initially supply no buffer to get the total buffer size required. This can return success instead of ERROR_MORE_DATA as previously expected; the actual result is the same, and we need to allocate a buffer large enough. Signed-off-by: Mark Yen Fixes: b7aa9dd964767d1d3d154037f188a9f8d44e063c --- src/go/wsl-helper/pkg/wsl-utils/version_windows.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/go/wsl-helper/pkg/wsl-utils/version_windows.go b/src/go/wsl-helper/pkg/wsl-utils/version_windows.go index 3f47ff2039a..787ae9dc702 100644 --- a/src/go/wsl-helper/pkg/wsl-utils/version_windows.go +++ b/src/go/wsl-helper/pkg/wsl-utils/version_windows.go @@ -59,7 +59,7 @@ func (i WSLInfo) String() string { if len(parts) == 0 { parts = append(parts, "not-installed") } - return fmt.Sprintf("Version=%s (%s)", i.Version, strings.Join(parts, ", ")) + return fmt.Sprintf("Version=%s kernel=%s (%s)", i.Version, i.KernelVersion, strings.Join(parts, ", ")) } const ( @@ -403,7 +403,7 @@ func getInboxWSLInfo(ctx context.Context, log *logrus.Entry) (bool, *PackageVers ) switch rv { case uintptr(windows.ERROR_SUCCESS): - kernelVersion, err = getMSIVersion(productCode) + kernelVersion, err = getMSIVersion(productCode, log) if err != nil { allErrors = append(allErrors, fmt.Errorf("error getting kernel version: %w", err)) } @@ -419,7 +419,7 @@ func getInboxWSLInfo(ctx context.Context, log *logrus.Entry) (bool, *PackageVers } // Get the version of an installed MSI package, given its product code. -func getMSIVersion(productCode []uint16) (*PackageVersion, error) { +func getMSIVersion(productCode []uint16, log *logrus.Entry) (*PackageVersion, error) { version := PackageVersion{} versionStringWide, err := windows.UTF16PtrFromString(INSTALLPROPERTY_VERSIONSTRING) if err != nil { @@ -436,7 +436,8 @@ func getMSIVersion(productCode []uint16) (*PackageVersion, error) { ) switch rv { case uintptr(windows.ERROR_SUCCESS): - return nil, fmt.Errorf("succeeded getting product version with no buffer") + log.WithFields(logrus.Fields{"bufSize": bufSize}).Trace("unexpected success, assuming needs more data") + fallthrough case uintptr(windows.ERROR_MORE_DATA): wideBuf = make([]uint16, bufSize+1) // Add space for null terminator bufSize = len(wideBuf)