diff options
Diffstat (limited to 'usr.bin/ar/write.c')
-rw-r--r-- | usr.bin/ar/write.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/usr.bin/ar/write.c b/usr.bin/ar/write.c index f78fbda36ba7..96f419909489 100644 --- a/usr.bin/ar/write.c +++ b/usr.bin/ar/write.c @@ -124,6 +124,7 @@ create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime) 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, const char *name, time_t mtime) 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, const char *name, time_t mtime) } 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); |