diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-03-06 00:59:08 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-03-06 00:59:08 +0000 |
commit | eec560a7c3d39c4df33de9f491596645da8bd368 (patch) | |
tree | 62b405ebb27b4d6d40fcfa902de5cf4be1b1acdc /lib/libarchive/archive_read_support_format_cpio.c | |
parent | 166d1b785d9d6de2ff3af1c42e56775618fddf06 (diff) | |
download | FreeBSD-src-eec560a7c3d39c4df33de9f491596645da8bd368.zip FreeBSD-src-eec560a7c3d39c4df33de9f491596645da8bd368.tar.gz |
Correctly read symlinks from cpio files.
While I'm here, fix a bug in reading filenames from
cpio files. (Copy should count the length of the name,
not the number of bytes available for input.)
Diffstat (limited to 'lib/libarchive/archive_read_support_format_cpio.c')
-rw-r--r-- | lib/libarchive/archive_read_support_format_cpio.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/libarchive/archive_read_support_format_cpio.c b/lib/libarchive/archive_read_support_format_cpio.c index 8fb0437..3775d23 100644 --- a/lib/libarchive/archive_read_support_format_cpio.c +++ b/lib/libarchive/archive_read_support_format_cpio.c @@ -27,6 +27,8 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include <sys/stat.h> + #ifdef DMALLOC #include <dmalloc.h> #endif @@ -145,9 +147,21 @@ archive_read_format_cpio_read_header(struct archive *a, if (bytes < namelength) return (ARCHIVE_FATAL); (a->compression_read_consume)(a, namelength); - archive_strncpy(&a->entry_name, h, bytes); + archive_strncpy(&a->entry_name, h, namelength); archive_entry_set_pathname(entry, a->entry_name.s); + /* If this is a symlink, read the link contents. */ + if (S_ISLNK(st.st_mode)) { + bytes = (a->compression_read_ahead)(a, &h, + a->entry_bytes_remaining); + if (bytes < a->entry_bytes_remaining) + return (ARCHIVE_FATAL); + (a->compression_read_consume)(a, a->entry_bytes_remaining); + archive_strncpy(&a->entry_linkname, h, a->entry_bytes_remaining); + archive_entry_set_symlink(entry, a->entry_linkname.s); + a->entry_bytes_remaining = 0; + } + /* Compare name to "TRAILER!!!" to test for end-of-archive. */ if (namelength == 11 && strcmp(h,"TRAILER!!!")==0) { /* TODO: Store file location of start of block. */ |