From efd756bee242b17e531f3edf9be17af11b341166 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Fri, 6 May 2016 13:51:56 -0400 Subject: [PATCH] Add test case for SCHILY.xattr support Add a test case for the SCHILY.xattr support. We test whether the provided archive's PAX header is parsed correctly. Signed-off-by: Stefan Berger --- Makefile.am | 1 + libarchive/test/CMakeLists.txt | 1 + libarchive/test/test_read_pax_schily_xattr.c | 70 ++++++ .../test/test_read_pax_schily_xattr.tar.uu | 231 ++++++++++++++++++ 4 files changed, 303 insertions(+) create mode 100644 libarchive/test/test_read_pax_schily_xattr.c create mode 100644 libarchive/test/test_read_pax_schily_xattr.tar.uu diff --git a/Makefile.am b/Makefile.am index 580fa2a6e..f92d723a4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -497,6 +497,7 @@ libarchive_test_SOURCES= \ libarchive/test/test_read_format_zip_winzip_aes_large.c \ libarchive/test/test_read_format_zip_zip64.c \ libarchive/test/test_read_large.c \ + libarchive/test/test_read_pax_schily_xattr.c \ libarchive/test/test_read_pax_truncated.c \ libarchive/test/test_read_position.c \ libarchive/test/test_read_set_format.c \ diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index 2f0e9e7b3..06b27638e 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -183,6 +183,7 @@ IF(ENABLE_TEST) test_read_format_zip_winzip_aes_large.c test_read_format_zip_zip64.c test_read_large.c + test_read_pax_schily_xattr.c test_read_pax_truncated.c test_read_position.c test_read_set_format.c diff --git a/libarchive/test/test_read_pax_schily_xattr.c b/libarchive/test/test_read_pax_schily_xattr.c new file mode 100644 index 000000000..7554f6d5d --- /dev/null +++ b/libarchive/test/test_read_pax_schily_xattr.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2016 IBM Corporation + * Copyright (c) 2003-2007 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. + * + * This test case's code has been derived from test_entry.c + */ +#include "test.h" + +DEFINE_TEST(test_schily_xattr_pax) +{ + struct archive *a; + struct archive_entry *ae; + const char *refname = "test_read_pax_schily_xattr.tar"; + const char *xname; /* For xattr tests. */ + const void *xval; /* For xattr tests. */ + size_t xsize; /* For xattr tests. */ + const char *string, *array; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); + + extract_reference_file(refname); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(2, archive_entry_xattr_count(ae)); + assertEqualInt(2, archive_entry_xattr_reset(ae)); + + assertEqualInt(0, archive_entry_xattr_next(ae, &xname, &xval, &xsize)); + assertEqualString(xname, "security.selinux"); + string = "system_u:object_r:unlabeled_t:s0"; + assertEqualString(xval, string); + /* the xattr's value also contains the terminating \0 */ + assertEqualInt((int)xsize, strlen(string) + 1); + + assertEqualInt(0, archive_entry_xattr_next(ae, &xname, &xval, &xsize)); + assertEqualString(xname, "security.ima"); + assertEqualInt((int)xsize, 265); + /* we only compare the first 12 bytes */ + array = "\x03\x02\x04\xb0\xe9\xd6\x79\x01\x00\x2b\xad\x1e"; + assertEqualMem(xval, array, 12); + + /* Close the archive. */ + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} diff --git a/libarchive/test/test_read_pax_schily_xattr.tar.uu b/libarchive/test/test_read_pax_schily_xattr.tar.uu new file mode 100644 index 000000000..52f7a8f0d --- /dev/null +++ b/libarchive/test/test_read_pax_schily_xattr.tar.uu @@ -0,0 +1,231 @@ +begin 644 test_schily_xattr_pax.tar +M+B]087A(96%D97)S+C$U,C4O8V]N9F9I;&5S```````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````#`P,#`V-#0`,#`P,#`P,``P,#`P,#`P`#`P,#`P,#`P-C0W +M`#$R-S$R,C$P-3`V`#`Q,C4V-@`@>``````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````!UW6X5O?Y6: +M9^':P2MZR[4)$@W?)B6GX0U@<,0M%6YNMO%OG+IS%/.< +M,"A(N&S.F9]=!*5=\).X."2$GUGJ,0C:@+G#$M_E8UQP,LU-G(8IKW^K^<8* +M*3_.N0'%8.^$8S$`D9XOF+DK<<)U34U'_"O5/22YS96QI;G5X +M/7-Y