return log_device_debug_errno(dev, errno, "Failed to open \"%s\": %m", filename);
size = read(fd, buf, sizeof(buf));
- if (size < 18 || (size_t) size >= sizeof(buf))
- return -EIO;
+ if (size < 18)
+ return log_device_warning_errno(dev, SYNTHETIC_ERRNO(EIO),
+ "Short read from \"%s\"", filename);
+ assert((size_t) size <= sizeof buf);
ifs_str[0] = '\0';
while (pos + sizeof(struct usb_interface_descriptor) < (size_t) size &&
struct usb_interface_descriptor *desc;
char if_str[8];
- desc = (struct usb_interface_descriptor *) &buf[pos];
+ desc = (struct usb_interface_descriptor *) (buf + pos);
if (desc->bLength < 3)
break;
+ if (desc->bLength > size - sizeof(struct usb_interface_descriptor))
+ return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EIO),
+ "Corrupt data read from \"%s\"", filename);
pos += desc->bLength;
if (desc->bDescriptorType != USB_DT_INTERFACE)