diff options
author | kaiw <kaiw@FreeBSD.org> | 2008-02-24 17:57:29 +0000 |
---|---|---|
committer | kaiw <kaiw@FreeBSD.org> | 2008-02-24 17:57:29 +0000 |
commit | 9ba4f3d00623bf0256e4a363444823519f9fb8b1 (patch) | |
tree | 96e3b77a5404a6f6bff8a68f2903f78d7c30e370 | |
parent | f0743db21bebcf35233d72f18d78a6a37f77be1e (diff) | |
download | FreeBSD-src-9ba4f3d00623bf0256e4a363444823519f9fb8b1.zip FreeBSD-src-9ba4f3d00623bf0256e4a363444823519f9fb8b1.tar.gz |
Handle properly when insert zero size objects into the archive:
Do not mmap 0-size objects and do not try to extract symbol from
0-size objects, but do treat 0-size objects as qualified objects and
accept them as an archive member. (A member with only the header part)
Note that GNU binutils ar on FreeBSD ignores 0-size objects, but on
Linux it accepts them. [1] But, since this is a rare usage, we can
safely ignore the compatibility issue.
Reported by: Michael Plass <mfp49_freebsd [AT] plass-family [DOT] net>
Pointed out by: Michael Plass <mfp49_freebsd [AT] plass-family [DOT] net> [1]
Reviewed by: Michael Plass <mfp49_freebsd [AT] plass-family [DOT] net>
Reviewed by: jkoshy
Approved by: jkoshy (mentor)
-rw-r--r-- | usr.bin/ar/write.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/usr.bin/ar/write.c b/usr.bin/ar/write.c index 959fb68..2ead060 100644 --- a/usr.bin/ar/write.c +++ b/usr.bin/ar/write.c @@ -154,6 +154,12 @@ create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime) obj->mtime = sb.st_mtime; obj->dev = sb.st_dev; obj->ino = sb.st_ino; + + if (obj->size == 0) { + obj->maddr = NULL; + return(obj); + } + if ((obj->maddr = mmap(NULL, obj->size, PROT_READ, MAP_PRIVATE, obj->fd, (off_t)0)) == MAP_FAILED) { bsdar_warnc(bsdar, errno, "can't mmap file: %s", obj->name); @@ -427,14 +433,14 @@ write_cleanup(struct bsdar *bsdar) struct ar_obj *obj, *obj_temp; TAILQ_FOREACH_SAFE(obj, &bsdar->v_obj, objs, obj_temp) { - free(obj->name); if (obj->fd == -1) free(obj->maddr); else - if (munmap(obj->maddr, obj->size)) + if (obj->maddr != NULL && munmap(obj->maddr, obj->size)) bsdar_warnc(bsdar, errno, "can't munmap file: %s", obj->name); TAILQ_REMOVE(&bsdar->v_obj, obj, objs); + free(obj->name); free(obj); } @@ -478,7 +484,7 @@ write_objs(struct bsdar *bsdar) /* Create archive symbol table and archive string table, if need. */ TAILQ_FOREACH(obj, &bsdar->v_obj, objs) { - if (!(bsdar->options & AR_SS)) + if (!(bsdar->options & AR_SS) && obj->maddr != NULL) create_symtab_entry(bsdar, obj->maddr, obj->size); if (strlen(obj->name) > _MAXNAMELEN_SVR4) add_to_ar_str_table(bsdar, obj->name); |