From owner-svn-src-all@freebsd.org Thu Jul 28 15:17:13 2016 Return-Path: Delivered-To: svn-src-all@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 7E83DBA6197; Thu, 28 Jul 2016 15:17:13 +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 4E9821EC2; Thu, 28 Jul 2016 15:17:13 +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 u6SFHCne005617; Thu, 28 Jul 2016 15:17:12 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6SFHC6S005616; Thu, 28 Jul 2016 15:17:12 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201607281517.u6SFHC6S005616@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Thu, 28 Jul 2016 15:17:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r303443 - head/usr.bin/sed X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jul 2016 15:17:13 -0000 Author: ed Date: Thu Jul 28 15:17:12 2016 New Revision: 303443 URL: https://svnweb.freebsd.org/changeset/base/303443 Log: Don't call basename() and dirname() in an unportable way. POSIX allows these functions to modify their input buffer, so that they have storage for the return value. Pull copies of the filename before calling these utility functions. Modified: head/usr.bin/sed/main.c Modified: head/usr.bin/sed/main.c ============================================================================== --- head/usr.bin/sed/main.c Thu Jul 28 13:54:46 2016 (r303442) +++ head/usr.bin/sed/main.c Thu Jul 28 15:17:12 2016 (r303443) @@ -301,6 +301,7 @@ mf_fgets(SPACE *sp, enum e_spflag spflag { struct stat sb; ssize_t len; + char *dirbuf, *basebuf; static char *p = NULL; static size_t plen = 0; int c; @@ -389,9 +390,14 @@ mf_fgets(SPACE *sp, enum e_spflag spflag if ((size_t)len > sizeof(oldfname)) errx(1, "%s: name too long", fname); } + if ((dirbuf = strdup(fname)) == NULL || + (basebuf = strdup(fname)) == NULL) + err(1, "strdup"); len = snprintf(tmpfname, sizeof(tmpfname), - "%s/.!%ld!%s", dirname(fname), (long)getpid(), - basename(fname)); + "%s/.!%ld!%s", dirname(dirbuf), (long)getpid(), + basename(basebuf)); + free(dirbuf); + free(basebuf); if ((size_t)len >= sizeof(tmpfname)) errx(1, "%s: name too long", fname); unlink(tmpfname);