]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev/scsi_id: increase MAX_SERIAL_LEN from 256 to 512
authortuhaowen <tuhaowen@uniontech.com>
Wed, 31 Dec 2025 02:46:30 +0000 (10:46 +0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 Jan 2026 18:48:28 +0000 (03:48 +0900)
The current MAX_SERIAL_LEN value of 256 is insufficient for some SCSI
devices with non-standard serial number lengths. In do_scsi_page80_inquiry(),
the required buffer length is calculated as:

    len = 1 + VENDOR_LENGTH + MODEL_LENGTH + buf[3]
        = 1 + 8 + 16 + buf[3]
        = 25 + buf[3]

where buf[3] contains the serial number length reported by the device.
According to the SCSI specification, this field is an unsigned 8-bit
value, meaning it can theoretically be up to 255 bytes. This results
in a maximum required length of 280 bytes, exceeding the current limit
of 256 bytes.

When this occurs, scsi_id fails with an error message like:
    "length 256 too short - need 280"

This has been observed with certain vendor devices that report unusually
long serial numbers in VPD page 0x80.

Increase MAX_SERIAL_LEN to 512 to accommodate the maximum possible
serial number length plus all required prefixes (vendor, model, and
type identifiers), providing sufficient headroom for non-compliant
devices while maintaining reasonable memory usage.

Signed-off-by: tuhaowen <tuhaowen@uniontech.com>
src/udev/scsi_id/scsi_id.h

index 9ab33418559390cdd71d043811f9d0b926182a71..db49c7f3d955ce64f7035bea0d83c65100b70b6e 100644 (file)
@@ -17,7 +17,7 @@
  * MAX_SERIAL_LEN: the maximum length of the serial number, including
  * added prefixes such as vendor and product (model) strings.
  */
-#define MAX_SERIAL_LEN 256
+#define MAX_SERIAL_LEN 512
 
 /*
  * MAX_BUFFER_LEN: maximum buffer size and line length used while reading