summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsg <jsg@openbsd.org>2017-08-22 11:00:39 +0000
committerjsg <jsg@openbsd.org>2017-08-22 11:00:39 +0000
commitbded617dceb34a2cd5ec7e4a5964b206695b0969 (patch)
treee66ace39c8ba570c3fe7f970f22c403f10d6dc73
parentFix negative array index read. Coverity CID 1453243 and 1453334. (diff)
downloadwireguard-openbsd-bded617dceb34a2cd5ec7e4a5964b206695b0969.tar.xz
wireguard-openbsd-bded617dceb34a2cd5ec7e4a5964b206695b0969.zip
Move array bounds tests before access to avoid reading past the end of
an array. Coverity CIDs 1452968 1453000. ok jung@ who mentions this case isn't hit in practice due to arrays having a terminating NULL.
-rw-r--r--sys/dev/isa/asmc.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/dev/isa/asmc.c b/sys/dev/isa/asmc.c
index 4da10d44763..b3c06373417 100644
--- a/sys/dev/isa/asmc.c
+++ b/sys/dev/isa/asmc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asmc.c,v 1.31 2017/02/14 15:47:12 jcs Exp $ */
+/* $OpenBSD: asmc.c,v 1.32 2017/08/22 11:00:39 jsg Exp $ */
/*
* Copyright (c) 2015 Joerg Jung <jung@openbsd.org>
*
@@ -665,7 +665,7 @@ asmc_init(struct asmc_softc *sc)
int i, r;
/* number of temperature sensors depends on product */
- for (i = 0; sc->sc_prod->pr_temp[i] && i < ASMC_MAXTEMP; i++)
+ for (i = 0; i < ASMC_MAXTEMP && sc->sc_prod->pr_temp[i]; i++)
if ((r = asmc_temp(sc, i, 1)) && r != ASMC_NOTFOUND)
printf("%s: read temp %d failed (0x%x)\n",
sc->sc_dev.dv_xname, i, r);
@@ -707,7 +707,7 @@ asmc_update(void *arg)
struct asmc_softc *sc = arg;
int i;
- for (i = 0; sc->sc_prod->pr_temp[i] && i < ASMC_MAXTEMP; i++)
+ for (i = 0; i < ASMC_MAXTEMP && sc->sc_prod->pr_temp[i]; i++)
if (!(sc->sc_sensor_temp[i].flags & SENSOR_FINVALID))
asmc_temp(sc, i, 0);
for (i = 0; i < sc->sc_nfans && i < ASMC_MAXFAN; i++)