Skip to content

Commit

Permalink
vz: fix nil pointer dereference with mountType: reverse-sshfs
Browse files Browse the repository at this point in the history
```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x10075a5a4]

goroutine 1 [running]:
github.com/Code-Hex/vz/v3/internal/objc.ConvertToNSMutableArray.func1(0x2?, 0x600000c143f0?)
        /Users/suda/gopath/pkg/mod/github.com/!code-!hex/vz/v3@v3.0.2/internal/objc/objc.go:134 +0x24
github.com/Code-Hex/vz/v3/internal/objc.ConvertToNSMutableArray({0xc0002c85c0, 0x2, 0xc0001fdb20?})
        /Users/suda/gopath/pkg/mod/github.com/!code-!hex/vz/v3@v3.0.2/internal/objc/objc.go:134 +0xef
github.com/Code-Hex/vz/v3.(*VirtualMachineConfiguration).SetDirectorySharingDevicesVirtualMachineConfiguration(0xc00012e000?, {0xc0002c85a0, 0x2, 0x1f?})
        /Users/suda/gopath/pkg/mod/github.com/!code-!hex/vz/v3@v3.0.2/configuration.go:188 +0x77
github.com/lima-vm/lima/pkg/vz.attachFolderMounts(0xc00047e780, 0xb?)
        /Users/suda/gopath/src/github.com/lima-vm/lima/pkg/vz/vm_darwin.go:381 +0x214
github.com/lima-vm/lima/pkg/vz.createVM(0x1000811e5?, 0xc00012e040?)
        /Users/suda/gopath/src/github.com/lima-vm/lima/pkg/vz/vm_darwin.go:124 +0xf8
github.com/lima-vm/lima/pkg/vz.startVM({0x100b42d30?, 0xc0000da008}, 0xc00047e780)
        /Users/suda/gopath/src/github.com/lima-vm/lima/pkg/vz/vm_darwin.go:32 +0x5b
github.com/lima-vm/lima/pkg/vz.(*LimaVzDriver).Start(0xc0004b62b0, {0x100b42d30, 0xc0000da008})
        /Users/suda/gopath/src/github.com/lima-vm/lima/pkg/vz/vz_driver_darwin.go:106 +0xf3
github.com/lima-vm/lima/pkg/hostagent.(*HostAgent).Run(0xc0000e0480, {0x100b42d30?, 0xc0000da008})
        /Users
```

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Dec 14, 2022
1 parent 45cd9cf commit 7cf5a6a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/vz/vm_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func attachConsole(_ *driver.BaseDriver, vmConfig *vz.VirtualMachineConfiguratio
}

func attachFolderMounts(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineConfiguration) error {
mounts := make([]vz.DirectorySharingDeviceConfiguration, len(driver.Yaml.Mounts))
var mounts []vz.DirectorySharingDeviceConfiguration
if *driver.Yaml.MountType == limayaml.VIRTIOFS {
for i, mount := range driver.Yaml.Mounts {
expandedPath, err := localpathutil.Expand(mount.Location)
Expand Down Expand Up @@ -364,7 +364,7 @@ func attachFolderMounts(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineCo
return err
}
config.SetDirectoryShare(share)
mounts[i] = config
mounts = append(mounts, config)
}
}

Expand All @@ -378,7 +378,9 @@ func attachFolderMounts(driver *driver.BaseDriver, vmConfig *vz.VirtualMachineCo
}
}

vmConfig.SetDirectorySharingDevicesVirtualMachineConfiguration(mounts)
if len(mounts) > 0 {
vmConfig.SetDirectorySharingDevicesVirtualMachineConfiguration(mounts)
}
return nil
}

Expand Down

0 comments on commit 7cf5a6a

Please sign in to comment.