From eec560a7c3d39c4df33de9f491596645da8bd368 Mon Sep 17 00:00:00 2001 From: kientzle Date: Sat, 6 Mar 2004 00:59:08 +0000 Subject: 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.) --- lib/libarchive/archive_read_support_format_cpio.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib') 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 __FBSDID("$FreeBSD$"); +#include + #ifdef DMALLOC #include #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. */ -- cgit v1.1