svn commit: r300741 - head/usr.bin/ar
Ed Schouten
ed at FreeBSD.org
Thu May 26 13:49:42 UTC 2016
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);
More information about the svn-src-all
mailing list