From owner-svn-src-head@freebsd.org Thu May 26 13:49:42 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 16B28B4B29B; Thu, 26 May 2016 13:49:42 +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 C6FAF1FD0; Thu, 26 May 2016 13:49:41 +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 u4QDneiH059005; Thu, 26 May 2016 13:49:40 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4QDneJN059004; Thu, 26 May 2016 13:49:40 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201605261349.u4QDneJN059004@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Thu, 26 May 2016 13:49:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300741 - head/usr.bin/ar 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: Thu, 26 May 2016 13:49:42 -0000 Author: ed Date: Thu May 26 13:49:40 2016 New Revision: 300741 URL: https://svnweb.freebsd.org/changeset/base/300741 Log: Make code compile when basename() is POSIX compliant. In addition to the previous change I made to ar.c, pull in another basename() related fix. This change is similar to the one made to the ELF Toolchain version of ar, with the difference that the ELF Toolchain version lacks error handling for the strdup() call. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D6467 Modified: head/usr.bin/ar/write.c Modified: head/usr.bin/ar/write.c ============================================================================== --- head/usr.bin/ar/write.c Thu May 26 13:34:08 2016 (r300740) +++ head/usr.bin/ar/write.c Thu May 26 13:49:40 2016 (r300741) @@ -124,6 +124,7 @@ create_obj_from_file(struct bsdar *bsdar struct ar_obj *obj; struct stat sb; const char *bname; + char *tmpname; if (name == NULL) return (NULL); @@ -137,7 +138,10 @@ create_obj_from_file(struct bsdar *bsdar return (NULL); } - if ((bname = basename(name)) == NULL) + tmpname = strdup(name); + if (tmpname == NULL) + bsdar_errc(bsdar, EX_SOFTWARE, errno, "strdup failed"); + if ((bname = basename(tmpname)) == NULL) bsdar_errc(bsdar, EX_SOFTWARE, errno, "basename failed"); if (bsdar->options & AR_TR && strlen(bname) > _TRUNCATE_LEN) { if ((obj->name = malloc(_TRUNCATE_LEN + 1)) == NULL) @@ -147,6 +151,7 @@ create_obj_from_file(struct bsdar *bsdar } else if ((obj->name = strdup(bname)) == NULL) bsdar_errc(bsdar, EX_SOFTWARE, errno, "strdup failed"); + free(tmpname); if (fstat(obj->fd, &sb) < 0) { bsdar_warnc(bsdar, errno, "can't fstat file: %s", obj->name);