From owner-svn-src-stable@freebsd.org Fri Jul 31 00:21:41 2015 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 804DF9AFA4B; Fri, 31 Jul 2015 00:21:41 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 70B6E1A04; Fri, 31 Jul 2015 00:21:41 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6V0Lf9U013636; Fri, 31 Jul 2015 00:21:41 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6V0LfZZ013635; Fri, 31 Jul 2015 00:21:41 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201507310021.t6V0LfZZ013635@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Fri, 31 Jul 2015 00:21:41 +0000 (UTC) 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 X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Jul 2015 00:21:41 -0000 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); }