summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2015-03-31 13:38:28 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2015-03-31 13:38:28 +0000
commit51df407f9dd048978799102eccdd90a2becd485a (patch)
treec58d671ada29ddd89436cd8167a05b37294e7a28 /usr.sbin
parent45ed7dcb8b467803cac3e1e1d293362bb21e52dc (diff)
Do not iterate past the size of the array.
Found by naddy@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/usbdevs/usbdevs.c8
1 files changed, 6 insertions, 2 deletions
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 <errno.h>
#include <dev/usb/usb.h>
+#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) {