diff options
author | markj <markj@FreeBSD.org> | 2015-07-31 00:21:40 +0000 |
---|---|---|
committer | markj <markj@FreeBSD.org> | 2015-07-31 00:21:40 +0000 |
commit | 25eb055781934da19a92bbd651aac78be33104bf (patch) | |
tree | 25c2ac741cf51d6357a02e733f6ca1e6fc5c60f4 | |
parent | 21bbf441051190566f1ddc0b289d9a9314f0f143 (diff) | |
download | FreeBSD-src-25eb055781934da19a92bbd651aac78be33104bf.zip FreeBSD-src-25eb055781934da19a92bbd651aac78be33104bf.tar.gz |
MFC r285782:
Fix counter reads on platforms where sizeof(uint64_t) != sizeof(uint64_t *).
PR: 201700
-rw-r--r-- | usr.bin/netstat/main.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 1bfc951..6a1ab18 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -785,19 +785,31 @@ kread_counter(u_long addr) int kread_counters(u_long addr, void *buf, size_t size) { - uint64_t *c = buf; + uint64_t *c; + u_long *counters; + size_t i, n; if (kvmd_init() < 0) return (-1); - if (kread(addr, buf, size) < 0) + if (size % sizeof(uint64_t) != 0) { + warnx("kread_counters: invalid counter set size"); return (-1); + } - while (size != 0) { - *c = kvm_counter_u64_fetch(kvmd, *c); - size -= sizeof(*c); - c++; + n = size / sizeof(uint64_t); + if ((counters = malloc(n * sizeof(u_long))) == NULL) + err(-1, "malloc"); + if (kread(addr, counters, n * sizeof(u_long)) < 0) { + free(counters); + return (-1); } + + c = buf; + for (i = 0; i < n; i++) + c[i] = kvm_counter_u64_fetch(kvmd, counters[i]); + + free(counters); return (0); } |