The check compared bLength against (size - sizeof(descriptor)), which
is an absolute limit unrelated to the current buffer position. Since
bLength is uint8_t (max 255), this can never exceed size - 9 for any
realistic input, making the check dead code.
Use (size - pos) instead so the check actually catches descriptors
that extend past the end of the read data.
Fixes: https://github.com/systemd/systemd/issues/41570
desc = (struct usb_interface_descriptor *) (buf + pos);
if (desc->bLength < 3)
break;
- if (desc->bLength > size - sizeof(struct usb_interface_descriptor))
+ if (desc->bLength > (size_t) size - pos)
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EIO),
"Corrupt data read from \"%s\"", filename);
pos += desc->bLength;