diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2005-08-01 05:36:50 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2005-08-01 05:36:50 +0000 |
commit | 2e4c19f779ce48faaf5abcaa186def74956a6981 (patch) | |
tree | 2a7d441b21de326c5a27b994bce0b47dcb3dd0e7 /sys/dev/usb/ulpt.c | |
parent | 0fd85d9caed3489931a1fa9c2b7520960293653d (diff) |
Don't keep the devinfo string on the stack, instead use malloc/free.
This should cure some rare stack overflows.
From augustss NetBSD
ok dlg@ pascoe@
Diffstat (limited to 'sys/dev/usb/ulpt.c')
-rw-r--r-- | sys/dev/usb/ulpt.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/sys/dev/usb/ulpt.c b/sys/dev/usb/ulpt.c index 987633de297..7459cf346b8 100644 --- a/sys/dev/usb/ulpt.c +++ b/sys/dev/usb/ulpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ulpt.c,v 1.19 2004/07/08 22:18:44 deraadt Exp $ */ +/* $OpenBSD: ulpt.c,v 1.20 2005/08/01 05:36:49 brad Exp $ */ /* $NetBSD: ulpt.c,v 1.57 2003/01/05 10:19:42 scw Exp $ */ /* $FreeBSD: src/sys/dev/usb/ulpt.c,v 1.24 1999/11/17 22:33:44 n_hibma Exp $ */ @@ -207,16 +207,18 @@ USB_ATTACH(ulpt) usb_interface_descriptor_t *id, *iend; usb_config_descriptor_t *cdesc; usbd_status err; - char devinfo[1024]; + char *devinfop; usb_endpoint_descriptor_t *ed; u_int8_t epcount; int i, altno; DPRINTFN(10,("ulpt_attach: sc=%p\n", sc)); - usbd_devinfo(dev, 0, devinfo, sizeof devinfo); + + devinfop = usbd_devinfo_alloc(dev, 0); USB_ATTACH_SETUP; printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev), - devinfo, ifcd->bInterfaceClass, ifcd->bInterfaceSubClass); + devinfop, ifcd->bInterfaceClass, ifcd->bInterfaceSubClass); + usbd_devinfo_free(devinfop); /* XXX * Stepping through the alternate settings needs to be abstracted out. @@ -318,8 +320,8 @@ USB_ATTACH(ulpt) req.bRequest = UR_GET_DEVICE_ID; USETW(req.wValue, cd->bConfigurationValue); USETW2(req.wIndex, id->bInterfaceNumber, id->bAlternateSetting); - USETW(req.wLength, sizeof devinfo - 1); - err = usbd_do_request_flags(dev, &req, devinfo, USBD_SHORT_XFER_OK, + USETW(req.wLength, DEVINFOSIZE - 1); + err = usbd_do_request_flags(dev, &req, devinfop, USBD_SHORT_XFER_OK, &alen, USBD_DEFAULT_TIMEOUT); if (err) { printf("%s: cannot get device id\n", USBDEVNAME(sc->sc_dev)); @@ -327,13 +329,13 @@ USB_ATTACH(ulpt) printf("%s: empty device id, no printer connected?\n", USBDEVNAME(sc->sc_dev)); } else { - /* devinfo now contains an IEEE-1284 device ID */ - len = ((devinfo[0] & 0xff) << 8) | (devinfo[1] & 0xff); - if (len > sizeof devinfo - 3) - len = sizeof devinfo - 3; + /* devinfop now contains an IEEE-1284 device ID */ + len = ((devinfop[0] & 0xff) << 8) | (devinfop[1] & 0xff); + if (len > DEVINFOSIZE - 3) + len = DEVINFOSIZE - 3; devinfo[len] = 0; printf("%s: device id <", USBDEVNAME(sc->sc_dev)); - ieee1284_print_id(devinfo+2); + ieee1284_print_id(devinfop+2); printf(">\n"); } } |