Skip to content

Commit

Permalink
Merge pull request bugst#153 from cmaglie/fix_windows_enumerator
Browse files Browse the repository at this point in the history
windows: Avoid panic if USB Product name is empty
  • Loading branch information
cmaglie authored Jan 3, 2023
2 parents 0c6a048 + e6cff1a commit e381f2c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions enumerator/usb_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,12 @@ func retrievePortDetailsFromDevInfo(device *deviceInfo, details *PortDetails) er
the result of spdrpFriendlyName is therefore unique and suitable as an alternative string to for a port choice */
n := uint32(0)
setupDiGetDeviceRegistryProperty(device.set, &device.data, spdrpFriendlyName /* spdrpDeviceDesc */, nil, nil, 0, &n)
buff := make([]uint16, n*2)
buffP := (*byte)(unsafe.Pointer(&buff[0]))
if setupDiGetDeviceRegistryProperty(device.set, &device.data, spdrpFriendlyName /* spdrpDeviceDesc */, nil, buffP, n, &n) {
details.Product = syscall.UTF16ToString(buff[:])
if n > 0 {
buff := make([]uint16, n*2)
buffP := (*byte)(unsafe.Pointer(&buff[0]))
if setupDiGetDeviceRegistryProperty(device.set, &device.data, spdrpFriendlyName /* spdrpDeviceDesc */, nil, buffP, n, &n) {
details.Product = syscall.UTF16ToString(buff[:])
}
}

return nil
Expand Down

0 comments on commit e381f2c

Please sign in to comment.