From fc42ac3a5e49daf391af21ec7cce7d97ecf8af20 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Thu, 11 Jul 2024 18:38:43 -0400 Subject: [PATCH] fix(vm): panic when reading VM with SPICE USB passthrough (#1438) Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmox/nodes/vms/custom_usb_device.go | 2 +- proxmox/nodes/vms/custom_usb_device_test.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/proxmox/nodes/vms/custom_usb_device.go b/proxmox/nodes/vms/custom_usb_device.go index e141c43d..51f70826 100644 --- a/proxmox/nodes/vms/custom_usb_device.go +++ b/proxmox/nodes/vms/custom_usb_device.go @@ -77,7 +77,7 @@ func (r *CustomUSBDevice) UnmarshalJSON(b []byte) error { for _, p := range pairs { v := strings.Split(strings.TrimSpace(p), "=") if len(v) == 1 { - r.HostDevice = &v[1] + r.HostDevice = &v[0] } else if len(v) == 2 { switch v[0] { case "host": diff --git a/proxmox/nodes/vms/custom_usb_device_test.go b/proxmox/nodes/vms/custom_usb_device_test.go index d1629ba9..4725b6eb 100644 --- a/proxmox/nodes/vms/custom_usb_device_test.go +++ b/proxmox/nodes/vms/custom_usb_device_test.go @@ -46,6 +46,13 @@ func TestCustomUSBDevice_UnmarshalJSON(t *testing.T) { USB3: types.CustomBool(false).Pointer(), }, }, + { + name: "spice usb device", + line: `"spice"`, + want: &CustomUSBDevice{ + HostDevice: ptr.Ptr("spice"), + }, + }, } for _, tt := range tests {