From: "Theo de Raadt" Subject: Re: USB vendor/product sanitization To: Greg Steuck Cc: tech@openbsd.org Date: Sat, 15 Aug 2026 09:59:39 -0600 I like this. Greg Steuck wrote: > 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 */ > } > >