Files
omarchy-pkgs/pkgbuilds/linux-omarchy/0620-usb-string-sanitize.patch
T

30 lines
893 B
Diff

diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1052,6 +1052,25 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
UTF16_LITTLE_ENDIAN, buf, size);
buf[err] = 0;
+ /*
+ * Some devices report string descriptors with a declared length
+ * greater than the actual serial, leaving uninitialized firmware
+ * memory (often including C0 control characters) appended to the
+ * returned string. Truncate at the first control character so
+ * callers get a clean, well-formed string.
+ */
+ {
+ int i;
+ for (i = 0; i < err; i++) {
+ unsigned char c = buf[i];
+ if (c < 0x20 || c == 0x7f) {
+ buf[i] = 0;
+ err = i;
+ break;
+ }
+ }
+ }
+
if (tbuf[1] != USB_DT_STRING)
dev_dbg(&dev->dev,
"wrong descriptor type %02x for string %d (\"%s\")\n",