diff options
author | kientzle <kientzle@FreeBSD.org> | 2007-10-12 04:11:31 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2007-10-12 04:11:31 +0000 |
commit | c2c3c21fbd0bf2438613a57927c47131c1d18584 (patch) | |
tree | 618f1cb77b35adb6ee46e91ba038bd19e0ba563f /lib/libarchive/test/test_write_format_cpio.c | |
parent | 7f137794299c6358dee3eb8be2af419fcf98250d (diff) | |
download | FreeBSD-src-c2c3c21fbd0bf2438613a57927c47131c1d18584.zip FreeBSD-src-c2c3c21fbd0bf2438613a57927c47131c1d18584.tar.gz |
Correct the cpio writers to not accept data for non-regular files.
In particular, the previous code led to archives that had
non-empty bodies following directory entries. Not a fatal
problem, as bsdtar and GNU cpio are both happy to just skip
this bogus data, but it still shouldn't be there.
MFC after: 3 days
Diffstat (limited to 'lib/libarchive/test/test_write_format_cpio.c')
-rw-r--r-- | lib/libarchive/test/test_write_format_cpio.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/libarchive/test/test_write_format_cpio.c b/lib/libarchive/test/test_write_format_cpio.c index 2ea40a3..886942e 100644 --- a/lib/libarchive/test/test_write_format_cpio.c +++ b/lib/libarchive/test/test_write_format_cpio.c @@ -66,6 +66,21 @@ test_format(int (*set_format)(struct archive *)) archive_entry_free(ae); assertA(8 == archive_write_data(a, "12345678", 9)); + /* + * Write a directory to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 11, 110); + archive_entry_copy_pathname(ae, "dir"); + archive_entry_set_mode(ae, S_IFDIR | 0755); + archive_entry_set_size(ae, 512); + + assertA(0 == archive_write_header(a, ae)); + assertEqualInt(0, archive_entry_size(ae)); + archive_entry_free(ae); + assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9)); + + /* Close out the archive. */ assertA(0 == archive_write_close(a)); #if ARCHIVE_API_VERSION > 1 @@ -95,8 +110,21 @@ test_format(int (*set_format)(struct archive *)) assertA(8 == archive_read_data(a, filedata, 10)); assert(0 == memcmp(filedata, "12345678", 8)); + /* + * Read the dir entry back. + */ + assertA(0 == archive_read_next_header(a, &ae)); + assert(11 == archive_entry_mtime(ae)); + assert(0 == archive_entry_mtime_nsec(ae)); + assert(0 == archive_entry_atime(ae)); + assert(0 == archive_entry_ctime(ae)); + assertEqualString("dir", archive_entry_pathname(ae)); + assert((S_IFDIR | 0755) == archive_entry_mode(ae)); + assertEqualInt(0, archive_entry_size(ae)); + assertEqualIntA(a, 0, archive_read_data(a, filedata, 10)); + /* Verify the end of the archive. */ - assert(1 == archive_read_next_header(a, &ae)); + assertEqualIntA(a, 1, archive_read_next_header(a, &ae)); assert(0 == archive_read_close(a)); #if ARCHIVE_API_VERSION > 1 assert(0 == archive_read_finish(a)); |