summaryrefslogtreecommitdiffstats
path: root/usr.bin/top/machine.c
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2008-04-11 11:34:09 +0000
committerru <ru@FreeBSD.org>2008-04-11 11:34:09 +0000
commite8bab4ec9bfbdcd70ae3a9eabbc9e47efee5658f (patch)
tree8cc36b6a75f76ea80811e640e512b9504c53d911 /usr.bin/top/machine.c
parente7012ad33098903c6d2cd65d0210c9e2ad229c7f (diff)
downloadFreeBSD-src-e8bab4ec9bfbdcd70ae3a9eabbc9e47efee5658f.zip
FreeBSD-src-e8bab4ec9bfbdcd70ae3a9eabbc9e47efee5658f.tar.gz
Allocate enough memory for pcpu_cp_time[] to stop sysctl() from
writing outside of array bounds. This fully fixes -P display on i386, where kern.cp_times prints zeroes for non-existing CPUs.
Diffstat (limited to 'usr.bin/top/machine.c')
-rw-r--r--usr.bin/top/machine.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 21bf033..632d53d 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -312,6 +312,7 @@ machine_init(struct statics *statics, char do_unames)
err(1, "malloc %zd bytes", size);
if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1)
err(1, "sysctlbyname kern.cp_times");
+ pcpu_cp_time = calloc(1, size);
maxid = (size / CPUSTATES / sizeof(long)) - 1;
for (i = 0; i <= maxid; i++) {
empty = 1;
@@ -335,7 +336,6 @@ machine_init(struct statics *statics, char do_unames)
Header_lines += ncpus - 1; /* 7 */
}
size = sizeof(long) * ncpus * CPUSTATES;
- pcpu_cp_time = calloc(1, size);
pcpu_cp_old = calloc(1, size);
pcpu_cp_diff = calloc(1, size);
pcpu_cpu_states = calloc(1, size);
OpenPOWER on IntegriCloud