From b5cd11a017711a0c099d75adda38fc37e2077dbe Mon Sep 17 00:00:00 2001 From: mpi Date: Tue, 31 Mar 2015 13:38:27 +0000 Subject: Do not iterate past the size of the array. Found by naddy@ --- usr.sbin/usbdevs/usbdevs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'usr.sbin/usbdevs/usbdevs.c') diff --git a/usr.sbin/usbdevs/usbdevs.c b/usr.sbin/usbdevs/usbdevs.c index 6d4dbe0c9e8..7962dc22e5f 100644 --- a/usr.sbin/usbdevs/usbdevs.c +++ b/usr.sbin/usbdevs/usbdevs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdevs.c,v 1.23 2015/02/09 23:00:15 deraadt Exp $ */ +/* $OpenBSD: usbdevs.c,v 1.24 2015/03/31 13:38:27 mpi Exp $ */ /* $NetBSD: usbdevs.c,v 1.19 2002/02/21 00:34:31 christos Exp $ */ /* @@ -40,6 +40,10 @@ #include #include +#ifndef nitems +#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) +#endif + #define USBDEV "/dev/usb" int verbose = 0; @@ -123,7 +127,7 @@ usbdev(int f, int a, int rec) } if (!rec) return; - for (p = 0; p < di.udi_nports; p++) { + for (p = 0; p < di.udi_nports && p < nitems(di.udi_ports); p++) { int s = di.udi_ports[p]; if (s >= USB_MAX_DEVICES) { -- cgit v1.2.3-59-g8ed1b