From owner-svn-src-stable@freebsd.org Sat May 6 02:43:27 2017 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 F23FCD60065; Sat, 6 May 2017 02:43:27 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 C6AAB117; Sat, 6 May 2017 02:43:27 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v462hQKf097780; Sat, 6 May 2017 02:43:26 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v462hQIk097779; Sat, 6 May 2017 02:43:26 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201705060243.v462hQIk097779@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Sat, 6 May 2017 02:43:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r317861 - stable/11/usr.sbin/pmcstat X-SVN-Group: stable-11 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.23 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: Sat, 06 May 2017 02:43:28 -0000 Author: pfg Date: Sat May 6 02:43:26 2017 New Revision: 317861 URL: https://svnweb.freebsd.org/changeset/base/317861 Log: MFC r317284: pmcstat(8); unsign some allocation variables and use reallocarray(3). Use unsigned values in some internal variables that will be used during allocation. The variables are used in reduced scope and have no chance of becoming negative. Provide bounds checking through reallocarray(3). Modified: stable/11/usr.sbin/pmcstat/pmcpl_calltree.c stable/11/usr.sbin/pmcstat/pmcstat_log.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/pmcstat/pmcpl_calltree.c ============================================================================== --- stable/11/usr.sbin/pmcstat/pmcpl_calltree.c Sat May 6 02:39:11 2017 (r317860) +++ stable/11/usr.sbin/pmcstat/pmcpl_calltree.c Sat May 6 02:43:26 2017 (r317861) @@ -185,7 +185,7 @@ pmcpl_ct_samples_free(struct pmcpl_ct_sa static void pmcpl_ct_samples_grow(struct pmcpl_ct_sample *samples) { - int npmcs; + unsigned int npmcs; /* Enough storage. */ if (pmcstat_npmcs <= samples->npmcs) @@ -193,7 +193,7 @@ pmcpl_ct_samples_grow(struct pmcpl_ct_sa npmcs = samples->npmcs + max(pmcstat_npmcs - samples->npmcs, PMCPL_CT_GROWSIZE); - samples->sb = realloc(samples->sb, npmcs * sizeof(unsigned)); + samples->sb = reallocarray(samples->sb, npmcs, sizeof(unsigned)); if (samples->sb == NULL) errx(EX_SOFTWARE, "ERROR: out of memory"); bzero((char *)samples->sb + samples->npmcs * sizeof(unsigned), @@ -226,13 +226,13 @@ pmcpl_ct_samples_root(struct pmcpl_ct_sa static void pmcpl_ct_arc_grow(int cursize, int *maxsize, struct pmcpl_ct_arc **items) { - int nmaxsize; + unsigned int nmaxsize; if (cursize < *maxsize) return; nmaxsize = *maxsize + max(cursize + 1 - *maxsize, PMCPL_CT_GROWSIZE); - *items = realloc(*items, nmaxsize * sizeof(struct pmcpl_ct_arc)); + *items = reallocarray(*items, nmaxsize, sizeof(struct pmcpl_ct_arc)); if (*items == NULL) errx(EX_SOFTWARE, "ERROR: out of memory"); bzero((char *)*items + *maxsize * sizeof(struct pmcpl_ct_arc), @@ -247,13 +247,13 @@ pmcpl_ct_arc_grow(int cursize, int *maxs static void pmcpl_ct_instr_grow(int cursize, int *maxsize, struct pmcpl_ct_instr **items) { - int nmaxsize; + unsigned int nmaxsize; if (cursize < *maxsize) return; nmaxsize = *maxsize + max(cursize + 1 - *maxsize, PMCPL_CT_GROWSIZE); - *items = realloc(*items, nmaxsize * sizeof(struct pmcpl_ct_instr)); + *items = reallocarray(*items, nmaxsize, sizeof(struct pmcpl_ct_instr)); if (*items == NULL) errx(EX_SOFTWARE, "ERROR: out of memory"); bzero((char *)*items + *maxsize * sizeof(struct pmcpl_ct_instr), Modified: stable/11/usr.sbin/pmcstat/pmcstat_log.c ============================================================================== --- stable/11/usr.sbin/pmcstat/pmcstat_log.c Sat May 6 02:39:11 2017 (r317860) +++ stable/11/usr.sbin/pmcstat/pmcstat_log.c Sat May 6 02:43:26 2017 (r317861) @@ -535,8 +535,8 @@ pmcstat_image_add_symbols(struct pmcstat * Allocate space for the new entries. */ firsttime = image->pi_symbols == NULL; - symptr = realloc(image->pi_symbols, - sizeof(*symptr) * (image->pi_symcount + nfuncsyms)); + symptr = reallocarray(image->pi_symbols, + image->pi_symcount + nfuncsyms, sizeof(*symptr)); if (symptr == image->pi_symbols) /* realloc() failed. */ return; image->pi_symbols = symptr; @@ -587,8 +587,8 @@ pmcstat_image_add_symbols(struct pmcstat * Return space to the system if there were duplicates. */ if (newsyms < nfuncsyms) - image->pi_symbols = realloc(image->pi_symbols, - sizeof(*symptr) * image->pi_symcount); + image->pi_symbols = reallocarray(image->pi_symbols, + image->pi_symcount, sizeof(*symptr)); /* * Keep the list of symbols sorted.