Skip to content

Commit 19d0a6e

Browse files
windows: Error instead of panic on invalid device descriptor from hub handle
#111 Co-authored-by: Erkki Silvola <eki833@gmail.com>
1 parent 2742e8f commit 19d0a6e

File tree

1 file changed

+10
-1
lines changed
  • src/platform/windows_winusb

1 file changed

+10
-1
lines changed

src/platform/windows_winusb/hub.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const DEVICE_IS_SUPER_SPEED_CAPABLE_OR_HIGHER: u32 = 0x02;
3636
const DEVICE_IS_OPERATING_AT_SUPER_SPEED_PLUS_OR_HIGHER: u32 = 0x04;
3737
const DEVICE_IS_SUPER_SPEED_PLUS_CAPABLE_OR_HIGHER: u32 = 0x08;
3838

39-
use crate::{Error, Speed};
39+
use crate::{descriptors::DESCRIPTOR_TYPE_DEVICE, Error, Speed};
4040

4141
use super::{
4242
cfgmgr32::DevInst,
@@ -83,6 +83,15 @@ impl HubHandle {
8383
);
8484

8585
if r == TRUE {
86+
if info.DeviceDescriptor.bDescriptorType != DESCRIPTOR_TYPE_DEVICE {
87+
// When the device is disconnected during this call, Windows is observed to
88+
// sometimes return an all-zero device descriptor.
89+
return Err(Error::new(
90+
std::io::ErrorKind::Other,
91+
"IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX returned an invalid device descriptor",
92+
));
93+
}
94+
8695
Ok(info)
8796
} else {
8897
let err = Error::last_os_error();

0 commit comments

Comments
 (0)