diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-06-18 04:13:11 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-06-18 04:13:11 +0000 |
commit | 1b766f5cef2c57334448f9401c6039bda013efa8 (patch) | |
tree | 445908bd60bb3e1659694779e8951aa3e6345056 | |
parent | 36d76bf27c1d9f525b8533a3e5f90ed8e8bd5cc6 (diff) |
Add missing check for i < dk_ndrive in 2 loops; closes PR 3322
-rw-r--r-- | usr.bin/vmstat/dkstats.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/usr.bin/vmstat/dkstats.c b/usr.bin/vmstat/dkstats.c index fccd1b58b92..406fa47e4d0 100644 --- a/usr.bin/vmstat/dkstats.c +++ b/usr.bin/vmstat/dkstats.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dkstats.c,v 1.22 2002/12/16 01:57:04 tdeval Exp $ */ +/* $OpenBSD: dkstats.c,v 1.23 2003/06/18 04:13:10 millert Exp $ */ /* $NetBSD: dkstats.c,v 1.1 1996/05/10 23:19:27 thorpej Exp $ */ /* @@ -192,10 +192,8 @@ dkreadstats(void) if (sysctl(mib, 2, disknames, &size, NULL, 0) < 0) err(1, "can't get hw.disknames"); bufpp = disknames; - i = 0; - while ((name = strsep(&bufpp, ",")) != NULL) { - dk_name[i++] = name; - } + for (i = 0; i < dk_ndrive && (name = strsep(&bufpp, ",")) != NULL; i++) + dk_name[i] = name; disknames = cur.dk_name[0]; /* To free old names. */ if (dk_ndrive < cur.dk_ndrive) { @@ -474,10 +472,9 @@ dkinit(int select) if (sysctl(mib, 2, disknames, &size, NULL, 0) < 0) err(1, "can't get hw.disknames"); bufpp = disknames; - i = 0; - while ((name = strsep(&bufpp, ",")) != NULL) { - cur.dk_name[i] = name; - cur.dk_select[i++] = select; + for (i = 0; i < dk_ndrive && (name = strsep(&bufpp, ",")) != NULL; i++) { + cur.dk_name[i] = name; + cur.dk_select[i] = select; } } else { #if !defined(NOKVM) |