Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 May 2016 13:49:40 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r300741 - head/usr.bin/ar
Message-ID:  <201605261349.u4QDneJN059004@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605261349.u4QDneJN059004>