diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | libarchive/archive_read.c | 30 | ||||
-rw-r--r-- | libarchive/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libarchive/test/main.c | 4 | ||||
-rw-r--r-- | libarchive/test/test_archive_read_close_twice_open_fd.c | 9 | ||||
-rw-r--r-- | libarchive/test/test_archive_read_close_twice_open_filename.c | 9 | ||||
-rw-r--r-- | libarchive/test/test_archive_read_next_header_empty.c | 111 | ||||
-rw-r--r-- | libarchive/test/test_read_pax_truncated.c | 86 | ||||
-rw-r--r-- | libarchive/test/test_read_truncated.c | 48 |
9 files changed, 213 insertions, 86 deletions
diff --git a/Makefile.am b/Makefile.am index 2470114a..32a2ed09 100644 --- a/Makefile.am +++ b/Makefile.am @@ -248,6 +248,7 @@ libarchive_test_SOURCES= \ libarchive/test/test_archive_read_close_twice.c \ libarchive/test/test_archive_read_close_twice_open_fd.c \ libarchive/test/test_archive_read_close_twice_open_filename.c \ + libarchive/test/test_archive_read_next_header_empty.c \ libarchive/test/test_archive_set_error.c \ libarchive/test/test_bad_fd.c \ libarchive/test/test_compat_bzip2.c \ diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c index 75ac35b7..c9c495a7 100644 --- a/libarchive/archive_read.c +++ b/libarchive/archive_read.c @@ -318,7 +318,7 @@ archive_read_open2(struct archive *_a, void *client_data, { struct archive_read *a = (struct archive_read *)_a; struct archive_read_filter *filter; - int e; + int slot, e; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, "archive_read_open"); @@ -360,9 +360,19 @@ archive_read_open2(struct archive *_a, void *client_data, /* Build out the input pipeline. */ e = build_stream(a); - if (e == ARCHIVE_OK) - a->archive.state = ARCHIVE_STATE_HEADER; + if (e < ARCHIVE_WARN) { + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + + slot = choose_format(a); + if (slot < 0) { + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + a->format = &(a->formats[slot]); + a->archive.state = ARCHIVE_STATE_HEADER; return (e); } @@ -435,7 +445,7 @@ static int _archive_read_next_header2(struct archive *_a, struct archive_entry *entry) { struct archive_read *a = (struct archive_read *)_a; - int slot, ret; + int ret; archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, @@ -446,18 +456,6 @@ _archive_read_next_header2(struct archive *_a, struct archive_entry *entry) archive_clear_error(&a->archive); /* - * If no format has yet been chosen, choose one. - */ - if (a->format == NULL) { - slot = choose_format(a); - if (slot < 0) { - a->archive.state = ARCHIVE_STATE_FATAL; - return (ARCHIVE_FATAL); - } - a->format = &(a->formats[slot]); - } - - /* * If client didn't consume entire data, skip any remainder * (This is especially important for GNU incremental directories.) */ diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index 99deeff5..68e6fa9b 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -17,6 +17,7 @@ IF(ENABLE_TEST) test_archive_read_close_twice.c test_archive_read_close_twice_open_fd.c test_archive_read_close_twice_open_filename.c + test_archive_read_next_header_empty.c test_archive_set_error.c test_bad_fd.c test_compat_bzip2.c diff --git a/libarchive/test/main.c b/libarchive/test/main.c index 62f2c9b9..ee41e56f 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -524,7 +524,9 @@ assertion_equal_wstring(const char *file, int line, void *extra) { assertion_count(file, line); - if (v1 == v2 || wcscmp(v1, v2) == 0) + if (v1 == v2) + return (1); + if (v1 != NULL && v2 != NULL && wcscmp(v1, v2) == 0) return (1); failure_start(file, line, "%s != %s", e1, e2); wcsdump(e1, v1); diff --git a/libarchive/test/test_archive_read_close_twice_open_fd.c b/libarchive/test/test_archive_read_close_twice_open_fd.c index 25cd350b..d30735e4 100644 --- a/libarchive/test/test_archive_read_close_twice_open_fd.c +++ b/libarchive/test/test_archive_read_close_twice_open_fd.c @@ -30,17 +30,18 @@ DEFINE_TEST(test_archive_read_close_twice_open_fd) { struct archive* a = archive_read_new(); - assertEqualInt(0, archive_read_open_fd(a, 0, 0)); + assertEqualInt(ARCHIVE_OK, archive_read_support_format_empty(a)); + assertEqualInt(ARCHIVE_OK, archive_read_open_fd(a, 0, 0)); assertEqualInt(0, archive_errno(a)); assertEqualString(NULL, archive_error_string(a)); - assertEqualInt(0, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(0, archive_errno(a)); assertEqualString(NULL, archive_error_string(a)); - assertEqualInt(0, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(0, archive_errno(a)); assertEqualString(NULL, archive_error_string(a)); - archive_read_finish(a); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); } diff --git a/libarchive/test/test_archive_read_close_twice_open_filename.c b/libarchive/test/test_archive_read_close_twice_open_filename.c index d62f2e8e..456b6d68 100644 --- a/libarchive/test/test_archive_read_close_twice_open_filename.c +++ b/libarchive/test/test_archive_read_close_twice_open_filename.c @@ -30,17 +30,18 @@ DEFINE_TEST(test_archive_read_close_twice_open_filename) { struct archive* a = archive_read_new(); - assertEqualInt(0, archive_read_open_filename(a, 0, 0)); + assertEqualInt(ARCHIVE_OK, archive_read_support_format_empty(a)); + assertEqualInt(ARCHIVE_OK, archive_read_open_filename(a, 0, 0)); assertEqualInt(0, archive_errno(a)); assertEqualString(NULL, archive_error_string(a)); - assertEqualInt(0, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(0, archive_errno(a)); assertEqualString(NULL, archive_error_string(a)); - assertEqualInt(0, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(0, archive_errno(a)); assertEqualString(NULL, archive_error_string(a)); - archive_read_finish(a); + assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); } diff --git a/libarchive/test/test_archive_read_next_header_empty.c b/libarchive/test/test_archive_read_next_header_empty.c new file mode 100644 index 00000000..f650bccc --- /dev/null +++ b/libarchive/test/test_archive_read_next_header_empty.c @@ -0,0 +1,111 @@ +/*- + * Copyright (c) 2003-2011 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" +__FBSDID("$FreeBSD$"); + +static void +test_empty_file1(void) +{ + struct archive* a = archive_read_new(); + + /* Try opening an empty file with the raw handler. */ + assertEqualInt(ARCHIVE_OK, archive_read_support_format_raw(a)); + assertEqualInt(0, archive_errno(a)); + assertEqualString(NULL, archive_error_string(a)); + + /* Raw handler doesn't support empty files. */ + assertEqualInt(ARCHIVE_FATAL, archive_read_open_filename(a, "emptyfile", 0)); + assert(NULL != archive_error_string(a)); + + archive_read_free(a); +} + +static void +test_empty_file2(void) +{ + struct archive* a = archive_read_new(); + struct archive_entry* e; + + /* Try opening an empty file with raw and empty handlers. */ + assertEqualInt(ARCHIVE_OK, archive_read_support_format_raw(a)); + assertEqualInt(ARCHIVE_OK, archive_read_support_format_empty(a)); + assertEqualInt(0, archive_errno(a)); + assertEqualString(NULL, archive_error_string(a)); + + assertEqualInt(ARCHIVE_OK, archive_read_open_filename(a, "emptyfile", 0)); + assertEqualInt(0, archive_errno(a)); + assertEqualString(NULL, archive_error_string(a)); + + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &e)); + assertEqualInt(0, archive_errno(a)); + assertEqualString(NULL, archive_error_string(a)); + + archive_read_free(a); +} + +static void +test_empty_tarfile(void) +{ + struct archive* a = archive_read_new(); + struct archive_entry* e; + + /* Try opening an empty file with raw and empty handlers. */ + assertEqualInt(ARCHIVE_OK, archive_read_support_format_tar(a)); + assertEqualInt(0, archive_errno(a)); + assertEqualString(NULL, archive_error_string(a)); + + assertEqualInt(ARCHIVE_OK, archive_read_open_filename(a, "empty.tar", 0)); + assertEqualInt(0, archive_errno(a)); + assertEqualString(NULL, archive_error_string(a)); + + assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &e)); + assertEqualInt(0, archive_errno(a)); + assertEqualString(NULL, archive_error_string(a)); + + archive_read_free(a); +} + +/* 512 zero bytes. */ +static char nulls[512]; + +DEFINE_TEST(test_archive_read_next_header_empty) +{ + FILE *f; + + /* Create an empty file. */ + f = fopen("emptyfile", "wb"); + fclose(f); + + /* Create a file with 512 zero bytes. */ + f = fopen("empty.tar", "wb"); + assertEqualInt(512, fwrite(nulls, 1, 512, f)); + fclose(f); + + test_empty_file1(); + test_empty_file2(); + test_empty_tarfile(); + +} diff --git a/libarchive/test/test_read_pax_truncated.c b/libarchive/test/test_read_pax_truncated.c index 372adff2..076a7f02 100644 --- a/libarchive/test/test_read_pax_truncated.c +++ b/libarchive/test/test_read_pax_truncated.c @@ -37,8 +37,8 @@ DEFINE_TEST(test_read_pax_truncated) /* Create a new archive in memory. */ assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_pax(a)); - assertA(0 == archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_pax(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buff_size, &used)); @@ -54,10 +54,10 @@ DEFINE_TEST(test_read_pax_truncated) archive_entry_set_ctime(ae, 3, 4); archive_entry_set_mtime(ae, 5, 6); archive_entry_set_size(ae, filedata_size); - assertA(0 == archive_write_header(a, ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); archive_entry_free(ae); - assertA((ssize_t)filedata_size - == archive_write_data(a, filedata, filedata_size)); + assertEqualIntA(a, (int)filedata_size, + (int)archive_write_data(a, filedata, filedata_size)); /* Close out the archive. */ assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); @@ -67,10 +67,17 @@ DEFINE_TEST(test_read_pax_truncated) * verify that we get an appropriate error. */ for (i = 1; i < used + 100; i += 100) { assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == read_open_memory2(a, buff, i, 13)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + /* If it's truncated very early, the file type detection should fail. */ + if (i < 512) { + assertEqualIntA(a, ARCHIVE_FATAL, read_open_memory2(a, buff, i, 13)); + goto wrap_up; + } else { + assertEqualIntA(a, ARCHIVE_OK, read_open_memory2(a, buff, i, 13)); + } + /* If it's truncated in a header, the header read should fail. */ if (i < 1536) { assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); goto wrap_up; @@ -79,8 +86,9 @@ DEFINE_TEST(test_read_pax_truncated) assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); } + /* If it's truncated in the body, the body read should fail. */ if (i < 1536 + filedata_size) { - assertA(ARCHIVE_FATAL == archive_read_data(a, filedata, filedata_size)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, filedata, filedata_size)); goto wrap_up; } else { failure("Archive truncated to %d bytes", i); @@ -113,22 +121,28 @@ DEFINE_TEST(test_read_pax_truncated) /* Same as above, except skip the body instead of reading it. */ for (i = 1; i < used + 100; i += 100) { assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == read_open_memory(a, buff, i, 7)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + /* If it's truncated very early, file type detection should fail. */ + if (i < 512) { + assertEqualIntA(a, ARCHIVE_FATAL, read_open_memory(a, buff, i, 7)); + goto wrap_up2; + } else { + assertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, buff, i, 7)); + } if (i < 1536) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); goto wrap_up2; } else { assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); } if (i < 1536 + 512*((filedata_size+511)/512)) { - assertA(ARCHIVE_FATAL == archive_read_data_skip(a)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data_skip(a)); goto wrap_up2; } else { - assertA(ARCHIVE_OK == archive_read_data_skip(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); } /* Verify the end of the archive. */ @@ -157,9 +171,9 @@ DEFINE_TEST(test_read_pax_truncated) buff2[513] = '9'; buff2[514] = 'A'; /* Non-digit in size. */ assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff2, used)); assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); @@ -168,9 +182,9 @@ DEFINE_TEST(test_read_pax_truncated) memcpy(buff2, buff, buff_size); buff2[512] = 'A'; /* First character not a digit. */ assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff2, used)); assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); @@ -181,9 +195,9 @@ DEFINE_TEST(test_read_pax_truncated) buff2[i] = '9'; buff2[i] = ' '; assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff2, used)); assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); @@ -195,9 +209,9 @@ DEFINE_TEST(test_read_pax_truncated) buff2[514] = '9'; buff2[515] = ' '; assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff2, used)); assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); @@ -207,9 +221,9 @@ DEFINE_TEST(test_read_pax_truncated) buff2[512] = '1'; /* Too small. */ buff2[513] = ' '; assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff2, used)); assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); @@ -218,9 +232,9 @@ DEFINE_TEST(test_read_pax_truncated) memcpy(buff2, buff, buff_size); buff2[512] = ' '; /* No size given. */ assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff2, used)); assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); @@ -229,9 +243,9 @@ DEFINE_TEST(test_read_pax_truncated) memcpy(buff2, buff, buff_size); buff2[1024]++; /* Break the checksum. */ assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff2, used)); assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); diff --git a/libarchive/test/test_read_truncated.c b/libarchive/test/test_read_truncated.c index c7d20c0b..e254ba58 100644 --- a/libarchive/test/test_read_truncated.c +++ b/libarchive/test/test_read_truncated.c @@ -37,9 +37,9 @@ DEFINE_TEST(test_read_truncated) /* Create a new archive in memory. */ assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, sizeof(buff), &used)); /* * Write a file to it. @@ -50,9 +50,9 @@ DEFINE_TEST(test_read_truncated) for (i = 0; i < sizeof(buff2); i++) buff2[i] = (unsigned char)rand(); archive_entry_set_size(ae, sizeof(buff2)); - assertA(0 == archive_write_header(a, ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); archive_entry_free(ae); - assertA((int)sizeof(buff2) == archive_write_data(a, buff2, sizeof(buff2))); + assertEqualIntA(a, sizeof(buff2), archive_write_data(a, buff2, sizeof(buff2))); /* Close out the archive. */ assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); @@ -62,22 +62,21 @@ DEFINE_TEST(test_read_truncated) * verify that we get an appropriate error. */ for (i = 1; i < used + 100; i += 100) { assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, i)); - + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); if (i < 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_open_memory(a, buff, i)); goto wrap_up; } else { - assertA(0 == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, i)); } + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); if (i < 512 + sizeof(buff2)) { - assertA(ARCHIVE_FATAL == archive_read_data(a, buff2, sizeof(buff2))); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buff2, sizeof(buff2))); goto wrap_up; } else { - assertA((int)sizeof(buff2) == archive_read_data(a, buff2, sizeof(buff2))); + assertEqualIntA(a, sizeof(buff2), archive_read_data(a, buff2, sizeof(buff2))); } /* Verify the end of the archive. */ @@ -87,9 +86,9 @@ DEFINE_TEST(test_read_truncated) * does not return an error if it can't consume * it.) */ if (i < 512 + 512*((sizeof(buff2) + 511)/512) + 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); } else { - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); } wrap_up: assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); @@ -101,22 +100,21 @@ DEFINE_TEST(test_read_truncated) /* Same as above, except skip the body instead of reading it. */ for (i = 1; i < used + 100; i += 100) { assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, i)); - + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); if (i < 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_open_memory(a, buff, i)); goto wrap_up2; } else { - assertA(0 == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, i)); } + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); if (i < 512 + 512*((sizeof(buff2)+511)/512)) { - assertA(ARCHIVE_FATAL == archive_read_data_skip(a)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data_skip(a)); goto wrap_up2; } else { - assertA(ARCHIVE_OK == archive_read_data_skip(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); } /* Verify the end of the archive. */ @@ -126,9 +124,9 @@ DEFINE_TEST(test_read_truncated) * does not return an error if it can't consume * it.) */ if (i < 512 + 512*((sizeof(buff2) + 511)/512) + 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); } else { - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); } wrap_up2: assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); |