Skip to content

Commit

Permalink
WSL-Helper: Fix getting MSI version
Browse files Browse the repository at this point in the history
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 <[email protected]>
Fixes: b7aa9dd
  • Loading branch information
mook-as committed Mar 12, 2024
1 parent d4097c8 commit 1c334e8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/go/wsl-helper/pkg/wsl-utils/version_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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))
}
Expand All @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 1c334e8

Please sign in to comment.