]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: fix bounds check in dev_if_packed_info()
authorMilan Kyselica <mil.kyselica@gmail.com>
Thu, 9 Apr 2026 17:45:19 +0000 (19:45 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 9 Apr 2026 20:48:09 +0000 (21:48 +0100)
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
src/udev/udev-builtin-usb_id.c

index 80597ea89ee258a276c118f8668dbacb94745136..61250b7072fe03b37e5253fc6031e324820b1b00 100644 (file)
@@ -168,7 +168,7 @@ static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
                 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;