diff options
Diffstat (limited to 'contrib/libarchive/libarchive/test/test_read_truncated_filter.c')
-rw-r--r-- | contrib/libarchive/libarchive/test/test_read_truncated_filter.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/contrib/libarchive/libarchive/test/test_read_truncated_filter.c b/contrib/libarchive/libarchive/test/test_read_truncated_filter.c index 632638d6fe92..9c5348d935d2 100644 --- a/contrib/libarchive/libarchive/test/test_read_truncated_filter.c +++ b/contrib/libarchive/libarchive/test/test_read_truncated_filter.c @@ -25,7 +25,6 @@ */ #include "test.h" -__FBSDID("$FreeBSD$"); /* * Check that we generate an error message when reading a truncated @@ -41,7 +40,7 @@ test_truncation(const char *compression, char path[16]; char *buff, *data; size_t buffsize, datasize, used1; - int i, j, r, use_prog; + int i, r, use_prog; buffsize = 2000000; assert(NULL != (buff = (char *)malloc(buffsize))); @@ -81,7 +80,7 @@ test_truncation(const char *compression, archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 100; i++) { - sprintf(path, "%s%d", compression, i); + snprintf(path, sizeof(path), "%s%d", compression, i); archive_entry_copy_pathname(ae, path); failure("%s", path); if (!assertEqualIntA(a, ARCHIVE_OK, @@ -91,9 +90,7 @@ test_truncation(const char *compression, free(buff); return; } - for (j = 0; j < (int)datasize; ++j) { - data[j] = (char)(rand() % 256); - } + fill_with_pseudorandom_data(data, datasize); failure("%s", path); if (!assertEqualIntA(a, datasize, archive_write_data(a, data, datasize))) { @@ -111,8 +108,13 @@ test_truncation(const char *compression, assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1 - used1/64)); + r = archive_read_open_memory(a, buff, used1 - used1/64); + if (r != ARCHIVE_OK) { + assertEqualStringA(a, "truncated bzip2 input", + archive_error_string(a)); + goto out; + } + for (i = 0; i < 100; i++) { if (ARCHIVE_OK != archive_read_next_header(a, &ae)) { failure("Should have non-NULL error message for %s", @@ -120,7 +122,7 @@ test_truncation(const char *compression, assert(NULL != archive_error_string(a)); break; } - sprintf(path, "%s%d", compression, i); + snprintf(path, sizeof(path), "%s%d", compression, i); assertEqualString(path, archive_entry_pathname(ae)); if (datasize != (size_t)archive_read_data(a, data, datasize)) { failure("Should have non-NULL error message for %s", @@ -133,6 +135,7 @@ test_truncation(const char *compression, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +out: free(data); free(buff); } @@ -154,12 +157,12 @@ DEFINE_TEST(test_read_truncated_filter_gzip) DEFINE_TEST(test_read_truncated_filter_lzip) { - test_truncation("lzip", archive_write_add_filter_lzip, 0); + test_truncation("lzip", archive_write_add_filter_lzip, canLzip()); } DEFINE_TEST(test_read_truncated_filter_lzma) { - test_truncation("lzma", archive_write_add_filter_lzma, 0); + test_truncation("lzma", archive_write_add_filter_lzma, canLzma()); } DEFINE_TEST(test_read_truncated_filter_lzop) @@ -169,5 +172,5 @@ DEFINE_TEST(test_read_truncated_filter_lzop) DEFINE_TEST(test_read_truncated_filter_xz) { - test_truncation("xz", archive_write_add_filter_xz, 0); + test_truncation("xz", archive_write_add_filter_xz, canXz()); } |