Date: Fri, 31 Jul 2015 00:21:41 +0000 (UTC) From: Mark Johnston <markj@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r286099 - stable/10/usr.bin/netstat Message-ID: <201507310021.t6V0LfZZ013635@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markj Date: Fri Jul 31 00:21:40 2015 New Revision: 286099 URL: https://svnweb.freebsd.org/changeset/base/286099 Log: MFC r285782: Fix counter reads on platforms where sizeof(uint64_t) != sizeof(uint64_t *). PR: 201700 Modified: stable/10/usr.bin/netstat/main.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/netstat/main.c ============================================================================== --- stable/10/usr.bin/netstat/main.c Fri Jul 31 00:00:59 2015 (r286098) +++ stable/10/usr.bin/netstat/main.c Fri Jul 31 00:21:40 2015 (r286099) @@ -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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507310021.t6V0LfZZ013635>