diff options
author | 2014-09-01 16:02:06 +0000 | |
---|---|---|
committer | 2014-09-01 16:02:06 +0000 | |
commit | 204c7515b4c87e28dd1f764ff1bf4ec7193a2b36 (patch) | |
tree | c630136f9adb6ea1c4c58335dc307f5f684ce554 | |
parent | Convert ecparam to new option/usage handling. (diff) | |
download | wireguard-openbsd-204c7515b4c87e28dd1f764ff1bf4ec7193a2b36.tar.xz wireguard-openbsd-204c7515b4c87e28dd1f764ff1bf4ec7193a2b36.zip |
Set the configuration number and get the interface handle in attach(),
like urtwn(4) does, to prevent a null dereference of the configuration
descriptor.
Issue reported and fix tested by Ludovic Coues on misc@
-rw-r--r-- | sys/dev/usb/if_urtw.c | 43 | ||||
-rw-r--r-- | sys/dev/usb/if_urtwreg.h | 5 |
2 files changed, 15 insertions, 33 deletions
diff --git a/sys/dev/usb/if_urtw.c b/sys/dev/usb/if_urtw.c index 8ab6f4a6b44..7407a790b3a 100644 --- a/sys/dev/usb/if_urtw.c +++ b/sys/dev/usb/if_urtw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_urtw.c,v 1.47 2014/07/13 15:52:49 mpi Exp $ */ +/* $OpenBSD: if_urtw.c,v 1.48 2014/09/01 16:02:06 mpi Exp $ */ /*- * Copyright (c) 2009 Martynas Venckus <martynas@openbsd.org> @@ -608,6 +608,19 @@ urtw_attach(struct device *parent, struct device *self, void *aux) sc->sc_udev = uaa->device; sc->sc_hwrev = urtw_lookup(uaa->vendor, uaa->product)->rev; + if (usbd_set_config_no(sc->sc_udev, 1, 0) != 0) { + printf("%s: could not set configuration no\n", + sc->sc_dev.dv_xname); + return; + } + + /* Get the first interface handle. */ + if (usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface) != 0) { + printf("%s: could not get interface handle\n", + sc->sc_dev.dv_xname); + return; + } + printf("%s: ", sc->sc_dev.dv_xname); if (sc->sc_hwrev & URTW_HWREV_8187) { @@ -2297,20 +2310,6 @@ urtw_init(struct ifnet *ifp) sc->sc_txtimer = 0; if (!(sc->sc_flags & URTW_INIT_ONCE)) { - error = usbd_set_config_no(sc->sc_udev, URTW_CONFIG_NO, 0); - if (error != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - goto fail; - } - /* get the first interface handle */ - error = usbd_device2interface_handle(sc->sc_udev, - URTW_IFACE_INDEX, &sc->sc_iface); - if (error != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - goto fail; - } error = urtw_open_pipes(sc); if (error != 0) goto fail; @@ -3730,20 +3729,6 @@ urtw_8187b_init(struct ifnet *ifp) sc->sc_txtimer = 0; if (!(sc->sc_flags & URTW_INIT_ONCE)) { - error = usbd_set_config_no(sc->sc_udev, URTW_CONFIG_NO, 0); - if (error != 0) { - printf("%s: could not set configuration no\n", - sc->sc_dev.dv_xname); - goto fail; - } - /* Get the first interface handle. */ - error = usbd_device2interface_handle(sc->sc_udev, - URTW_IFACE_INDEX, &sc->sc_iface); - if (error != 0) { - printf("%s: could not get interface handle\n", - sc->sc_dev.dv_xname); - goto fail; - } error = urtw_open_pipes(sc); if (error != 0) goto fail; diff --git a/sys/dev/usb/if_urtwreg.h b/sys/dev/usb/if_urtwreg.h index fe1ca1e845d..11fcff41939 100644 --- a/sys/dev/usb/if_urtwreg.h +++ b/sys/dev/usb/if_urtwreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_urtwreg.h,v 1.15 2013/11/26 20:33:18 deraadt Exp $ */ +/* $OpenBSD: if_urtwreg.h,v 1.16 2014/09/01 16:02:06 mpi Exp $ */ /*- * Copyright (c) 2009 Martynas Venckus <martynas@openbsd.org> @@ -17,9 +17,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define URTW_CONFIG_NO 1 -#define URTW_IFACE_INDEX 0 - /* * Known hardware revisions. */ |