USB vendor/product sanitization

Greg Steuck <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
I noticed this oddity in my dmesg:
umass0 at uhub5 port 4 configuration 1 interface 0 "Obreey
 Verse
" rev 2.00/1.01 addr 9
umass0: using SCSI over Bulk-Only

Apparently the vendor stuck a trailing \n into both product and vendor
fields. We could trim them though I wonder if it's worth the trouble
(Linux dmesg similarly gets some empty lines). If it is then do we care
to do more than the bare minimum?

diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c
index 41a53dc1e49..960edba6bc2 100644
--- a/sys/dev/usb/usb_subr.c
+++ b/sys/dev/usb/usb_subr.c
@@ -197,16 +197,18 @@ usbd_get_string(struct usbd_device *dev, int si, char *buf, size_t buflen)
 static void
 usbd_trim_spaces(char *p)
 {
-	char *q, *e;
+	char *q, *e, c;
 
 	if (p == NULL)
 		return;
 	q = e = p;
 	while (*q == ' ')	/* skip leading spaces */
 		q++;
-	while ((*p = *q++))	/* copy string */
-		if (*p++ != ' ') /* remember last non-space */
+	while ((*p = *q++)) {	/* copy string */
+		c = *p++;
+		if (c != ' ' && c != '\n') /* remember last non-space */
 			e = p;
+	}
 	*e = 0;			/* kill trailing spaces */
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.