From owner-svn-src-head@freebsd.org Wed May 25 08:45:04 2016 Return-Path: Delivered-To: svn-src-head@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 B4009B49BA0; Wed, 25 May 2016 08:45:04 +0000 (UTC) (envelope-from ed@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 81AB211FE; Wed, 25 May 2016 08:45:04 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4P8j38G049161; Wed, 25 May 2016 08:45:03 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4P8j3Xg049160; Wed, 25 May 2016 08:45:03 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201605250845.u4P8j3Xg049160@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Wed, 25 May 2016 08:45:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300669 - head/usr.sbin/pmcstat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 May 2016 08:45:04 -0000 Author: ed Date: Wed May 25 08:45:03 2016 New Revision: 300669 URL: https://svnweb.freebsd.org/changeset/base/300669 Log: Make code compile when basename() is POSIX compliant. The POSIX basename() function is allowed to modify its input buffer, which means its argument is "char *". Pull a copy of the input string before computing the base. Reviewed by: jtl Differential Revision: https://reviews.freebsd.org/D6465 Modified: head/usr.sbin/pmcstat/pmcpl_gprof.c Modified: head/usr.sbin/pmcstat/pmcpl_gprof.c ============================================================================== --- head/usr.sbin/pmcstat/pmcpl_gprof.c Wed May 25 08:09:14 2016 (r300668) +++ head/usr.sbin/pmcstat/pmcpl_gprof.c Wed May 25 08:45:03 2016 (r300669) @@ -310,8 +310,9 @@ pmcstat_callgraph_do_gmon_arcs(void) void pmcpl_gmon_initimage(struct pmcstat_image *pi) { + const char *execpath; int count, nlen; - char *sn; + char *sn, *snbuf; char name[NAME_MAX]; /* @@ -321,9 +322,11 @@ pmcpl_gmon_initimage(struct pmcstat_imag * `basename(path)`+ "~" + NNN + ".gmon" till we get a free * entry. */ - if ((sn = basename(pmcstat_string_unintern(pi->pi_execpath))) == NULL) - err(EX_OSERR, "ERROR: Cannot process \"%s\"", - pmcstat_string_unintern(pi->pi_execpath)); + execpath = pmcstat_string_unintern(pi->pi_execpath); + if ((snbuf = strdup(execpath)) == NULL) + err(EX_OSERR, "ERROR: Cannot copy \"%s\"", execpath); + if ((sn = basename(snbuf)) == NULL) + err(EX_OSERR, "ERROR: Cannot process \"%s\"", execpath); nlen = strlen(sn); nlen = min(nlen, (int) (sizeof(name) - sizeof(".gmon"))); @@ -355,6 +358,7 @@ pmcpl_gmon_initimage(struct pmcstat_imag } } while (count > 0); } + free(snbuf); LIST_INIT(&pi->pi_gmlist); }