aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-14 01:03:02 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-14 01:03:02 +0100
commit5cb28dc91a2e23e6f8f7e875e2ea725634526dfe (patch)
tree2cdbff93cfe4518e7f527daca0c395db35ef0c49
parent76e9644ba9e7ce3535eb72ab041ac3be8486c22c (diff)
Add a test case for reading binary xattrs from pax/schily headers
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--tests/Makemodule.am8
-rw-r--r--tests/tar/CREDITS5
-rw-r--r--tests/tar/xattr/xattr-schily-binary.tarbin0 -> 3072 bytes
-rw-r--r--tests/tar_xattr_schily_bin.c72
4 files changed, 84 insertions, 1 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index 492744d..ce91ad3 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -81,6 +81,11 @@ test_tar_xattr_schily_LDADD = libtar.a libcompat.a
test_tar_xattr_schily_CPPFLAGS = $(AM_CPPFLAGS)
test_tar_xattr_schily_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
+test_tar_xattr_schily_bin_SOURCES = tests/tar_xattr_schily_bin.c
+test_tar_xattr_schily_bin_LDADD = libtar.a libcompat.a
+test_tar_xattr_schily_bin_CPPFLAGS = $(AM_CPPFLAGS)
+test_tar_xattr_schily_bin_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
+
fstree_fuzz_SOURCES = tests/fstree_fuzz.c
fstree_fuzz_LDADD = libfstree.a libcompat.a
@@ -93,6 +98,7 @@ check_PROGRAMS += test_get_path test_fstree_sort test_fstree_from_file
check_PROGRAMS += test_fstree_init test_tar_ustar test_tar_pax test_tar_gnu
check_PROGRAMS += test_tar_sparse_gnu test_tar_sparse_gnu1 test_tar_sparse_gnu2
check_PROGRAMS += test_tar_xattr_bsd test_tar_xattr_schily
+check_PROGRAMS += test_tar_xattr_schily_bin
check_SCRIPTS += tests/cantrbry.sh
noinst_PROGRAMS += fstree_fuzz tar_fuzz
@@ -103,7 +109,7 @@ TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file
TESTS += test_fstree_init test_tar_ustar test_tar_pax
TESTS += test_tar_gnu test_tar_sparse_gnu test_tar_sparse_gnu1
TESTS += test_tar_sparse_gnu2 test_tar_xattr_bsd test_tar_xattr_schily
-TESTS += tests/cantrbry.sh
+TESTS += test_tar_xattr_schily_bin tests/cantrbry.sh
endif
EXTRA_DIST += $(top_srcdir)/tests/tar $(top_srcdir)/tests/words.txt
diff --git a/tests/tar/CREDITS b/tests/tar/CREDITS
index e4b19b4..6d55a59 100644
--- a/tests/tar/CREDITS
+++ b/tests/tar/CREDITS
@@ -23,3 +23,8 @@ for those features:
In addition to that, the files in "file-size" are truncated, since we are only
interested in parsing the header.
+
+The following addtional files have been added:
+ - xattr/xattr-shily-binary.tar
+ Created from xattr/xattr-shily.tar by manually patching in a capability
+ xattr key/value pair.
diff --git a/tests/tar/xattr/xattr-schily-binary.tar b/tests/tar/xattr/xattr-schily-binary.tar
new file mode 100644
index 0000000..0312807
--- /dev/null
+++ b/tests/tar/xattr/xattr-schily-binary.tar
Binary files differ
diff --git a/tests/tar_xattr_schily_bin.c b/tests/tar_xattr_schily_bin.c
new file mode 100644
index 0000000..d8d5161
--- /dev/null
+++ b/tests/tar_xattr_schily_bin.c
@@ -0,0 +1,72 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * tar_xattr_schily_bin.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "tar.h"
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#define STR(x) #x
+#define STRVALUE(x) STR(x)
+
+#define TEST_PATH STRVALUE(TESTPATH)
+
+static FILE *open_read(const char *path)
+{
+ FILE *fp = fopen(path, "rb");
+
+ if (fp == NULL) {
+ perror(path);
+ exit(EXIT_FAILURE);
+ }
+
+ return fp;
+}
+
+static const uint8_t value[] = {
+ 0x00, 0x00, 0x00, 0x02,
+ 0x00, 0x30, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+};
+
+int main(void)
+{
+ tar_header_decoded_t hdr;
+ char buffer[6];
+ FILE *fp;
+
+ assert(chdir(TEST_PATH) == 0);
+
+ fp = open_read("xattr/xattr-schily-binary.tar");
+ assert(read_header(fp, &hdr) == 0);
+ assert(hdr.sb.st_mode == (S_IFREG | 0644));
+ assert(hdr.sb.st_uid == 01750);
+ assert(hdr.sb.st_gid == 01750);
+ assert(hdr.sb.st_size == 5);
+ assert(hdr.sb.st_mtime == 1543094477);
+ assert(hdr.mtime == 1543094477);
+ assert(strcmp(hdr.name, "input.txt") == 0);
+ assert(!hdr.unknown_record);
+ assert(read_retry("data0", fp, buffer, 5) == 0);
+ buffer[5] = '\0';
+ assert(strcmp(buffer, "test\n") == 0);
+
+ assert(hdr.xattr != NULL);
+ assert(strcmp(hdr.xattr->key, "security.capability") == 0);
+ assert(hdr.xattr->value_len == sizeof(value));
+ assert(memcmp(hdr.xattr->value, value, sizeof(value)) == 0);
+ assert(hdr.xattr->next == NULL);
+
+ clear_header(&hdr);
+ fclose(fp);
+ return EXIT_SUCCESS;
+}