Date: Sun, 28 May 2006 09:40:05 GMT From: Hans Petter Selasky <hselasky@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 98001 for review Message-ID: <200605280940.k4S9e5VQ000799@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=98001 Change 98001 by hselasky@hselasky_mini_itx on 2006/05/28 09:39:32 Add rangecheck for devinfo. Affected files ... .. //depot/projects/usb/src/sys/dev/usb/uhub.c#4 edit .. //depot/projects/usb/src/sys/dev/usb/ulpt.c#4 edit .. //depot/projects/usb/src/sys/dev/usb/usb_subr.c#4 edit .. //depot/projects/usb/src/sys/dev/usb/usb_subr.h#4 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb/uhub.c#4 (text+ko) ==== @@ -354,10 +354,8 @@ usb_device_request_t req; usb_hub_descriptor_t hubdesc; int port, nports, removable, pwrdly; - char devinfo[1024]; + char devinfo[256]; - /* XXX no range check for devinfo */ - DPRINTFN(1,("\n")); sc->sc_hub = udev; @@ -564,9 +562,9 @@ usbd_delay_ms(udev, pwrdly); } - usbd_devinfo(udev, 1, &devinfo[0]); - device_set_desc_copy(dev, &devinfo[0]); - device_printf(dev, "%s\n", &devinfo[0]); + usbd_devinfo(udev, 1, devinfo, sizeof(devinfo)); + device_set_desc_copy(dev, devinfo); + device_printf(dev, "%s\n", devinfo); device_printf(dev, "%d port%s with %d " "removable, %s powered\n", nports, (nports != 1) ? "s" : "", ==== //depot/projects/usb/src/sys/dev/usb/ulpt.c#4 (text+ko) ==== ==== //depot/projects/usb/src/sys/dev/usb/usb_subr.c#4 (text+ko) ==== @@ -189,28 +189,36 @@ } void -usbd_devinfo(struct usbd_device *udev, int showclass, char *cp) +usbd_devinfo(struct usbd_device *udev, int showclass, + char *dst_ptr, u_int16_t dst_len) { usb_device_descriptor_t *udd = &udev->ddesc; char vendor[USB_MAX_STRING_LEN]; char product[USB_MAX_STRING_LEN]; - int bcdDevice, bcdUSB; + u_int16_t bcdDevice, bcdUSB; usbd_devinfo_vp(udev, vendor, product, 1); - cp += sprintf(cp, "%s %s", vendor, product); + + bcdUSB = UGETW(udd->bcdUSB); + bcdDevice = UGETW(udd->bcdDevice); + if(showclass) { - cp += sprintf(cp, ", class %d/%d", - udd->bDeviceClass, udd->bDeviceSubClass); + snprintf(dst_ptr, dst_len, "%s %s, class %d/%d, rev %x.%02x/" + "%x.%02x, addr %d", vendor, product, + udd->bDeviceClass, udd->bDeviceSubClass, + (bcdUSB >> 8), bcdUSB & 0xFF, + (bcdDevice >> 8), bcdDevice & 0xFF, + udev->address); + } + else + { + snprintf(dst_ptr, dst_len, "%s %s, rev %x.%02x/" + "%x.%02x, addr %d", vendor, product, + (bcdUSB >> 8), bcdUSB & 0xFF, + (bcdDevice >> 8), bcdDevice & 0xFF, + udev->address); } - bcdUSB = UGETW(udd->bcdUSB); - bcdDevice = UGETW(udd->bcdDevice); - cp += sprintf(cp, ", rev "); - cp += usbd_printBCD(cp, bcdUSB); - *cp++ = '/'; - cp += usbd_printBCD(cp, bcdDevice); - cp += sprintf(cp, ", addr %d", udev->address); - *cp = 0; return; } @@ -1548,10 +1556,10 @@ void usbd_set_desc(device_t dev, struct usbd_device *udev) { - u_int8_t devinfo[1024]; + u_int8_t devinfo[256]; - usbd_devinfo(udev, 1, &devinfo[0]); - device_set_desc_copy(dev, &devinfo[0]); - device_printf(dev, "<%s>\n", &devinfo[0]); + usbd_devinfo(udev, 1, devinfo, sizeof(devinfo)); + device_set_desc_copy(dev, devinfo); + device_printf(dev, "<%s>\n", devinfo); return; } ==== //depot/projects/usb/src/sys/dev/usb/usb_subr.h#4 (text+ko) ==== @@ -457,7 +457,8 @@ /* routines from usb_subr.c */ void -usbd_devinfo(struct usbd_device *udev, int showclass, char *cp); +usbd_devinfo(struct usbd_device *udev, int showclass, + char *dst_ptr, u_int16_t dst_len); const char * usbd_errstr(usbd_status err);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200605280940.k4S9e5VQ000799>