summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/archivetest.c224
-rw-r--r--contrib/libarchive.spec249
-rw-r--r--contrib/oss-fuzz/corpus.zipbin0 -> 4675 bytes
-rw-r--r--contrib/oss-fuzz/libarchive_fuzzer.cc49
-rwxr-xr-xcontrib/oss-fuzz/oss-fuzz-build.sh16
-rw-r--r--contrib/shar/shar.111
-rw-r--r--contrib/shar/shar.c2
7 files changed, 477 insertions, 74 deletions
diff --git a/contrib/archivetest.c b/contrib/archivetest.c
new file mode 100644
index 00000000..e4a25e3c
--- /dev/null
+++ b/contrib/archivetest.c
@@ -0,0 +1,224 @@
+/*-
+ * Copyright (c) 2019 Martin Matuska
+ * 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.
+ */
+
+/*
+ * Archivetest verifies reading archives with libarchive
+ *
+ * It may be used to reproduce failures in testcases discovered by OSS-Fuzz
+ * https://github.com/google/oss-fuzz/blob/master/projects/libarchive
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <archive.h>
+#include <archive_entry.h>
+
+#if defined __MINGW32__
+#include <getopt.h>
+#endif
+
+static const char *errnostr(int e)
+{
+ char *estr;
+ switch(e) {
+ case ARCHIVE_EOF:
+ estr = "ARCHIVE_EOF";
+ break;
+ case ARCHIVE_OK:
+ estr = "ARCHIVE_OK";
+ break;
+ case ARCHIVE_WARN:
+ estr = "ARCHIVE_WARN";
+ break;
+ case ARCHIVE_RETRY:
+ estr = "ARCHIVE_RETRY";
+ break;
+ case ARCHIVE_FAILED:
+ estr = "ARCHIVE_FAILED";
+ break;
+ case ARCHIVE_FATAL:
+ estr = "ARCHIVE_FATAL";
+ break;
+ default:
+ estr = "Unknown";
+ break;
+ }
+ return (estr);
+}
+
+static void usage(const char *prog)
+{
+ fprintf(stderr, "Usage: %s [-f filename] [-h] [-q] [-s]\n", prog);
+}
+
+static void printhelp()
+{
+ fprintf(stdout, "archivetest: verify reading archives with "
+ "libarchive\n\n"
+ "Options:\n"
+ " -f filename Filename to verify\n"
+ " -h Show this help\n"
+ " -q Quiet mode\n"
+ " -s Verify only headers (skip data)\n\n"
+ "If no filename is specified, data is read from standard input.\n"
+ "\n%s\n", archive_version_details());
+}
+
+static int v_print(int verbose, const char *format, ...)
+{
+ int r = 0;
+
+ if (verbose) {
+ va_list args;
+
+ va_start(args, format);
+ r = vfprintf(stdout, format, args);
+ va_end(args);
+ }
+ return (r);
+}
+
+int main(int argc, char *argv[])
+{
+ struct archive *a;
+ struct archive_entry *entry;
+ char *filename;
+ const char *p;
+ char buffer[4096];
+ int c;
+ int v, skip_data;
+ int r = ARCHIVE_OK;
+ int format_printed;
+
+ filename = NULL;
+ skip_data = 0;
+ v = 1;
+
+ while ((c = getopt (argc, argv, "f:hqs")) != -1) {
+ switch (c) {
+ case 'f':
+ filename = optarg;
+ break;
+ case 'h':
+ printhelp();
+ exit(0);
+ case 'q':
+ v = 0;
+ break;
+ case 's':
+ skip_data = 1;
+ break;
+ case '?':
+ if (optopt == 'f')
+ fprintf(stderr, "Option -%c requires "
+ "an argument.\n", optopt);
+ else if (isprint(optopt))
+ fprintf(stderr, "Unknown option '-%c'"
+ ".\n", optopt);
+ else
+ fprintf(stderr, "Unknown option "
+ "character '\\x%x'.\n", optopt);
+ usage(argv[0]);
+ exit(1);
+ break;
+ default:
+ exit(1);
+ }
+ }
+
+ a = archive_read_new();
+
+ archive_read_support_filter_all(a);
+ archive_read_support_format_all(a);
+
+ v_print(v, "Data source: ");
+
+ if (filename == NULL) {
+ v_print(v, "standard input\n");
+ r = archive_read_open_fd(a, STDIN_FILENO, 4096);
+ } else {
+ v_print(v, "filename: %s\n", filename);
+ r = archive_read_open_filename(a, filename, 4096);
+ }
+
+ if (r != ARCHIVE_OK) {
+ archive_read_free(a);
+ fprintf(stderr, "Invalid or unsupported data source\n");
+ exit(1);
+ }
+
+ format_printed = 0;
+ c = 1;
+
+ while (1) {
+ r = archive_read_next_header(a, &entry);
+ if (r == ARCHIVE_FATAL) {
+ v_print(v, "Entry %d: fatal error reading "
+ "header\n", c);
+ break;
+ }
+ if (!format_printed) {
+ v_print(v, "Filter: %s\nFormat: %s\n",
+ archive_filter_name(a, 0), archive_format_name(a));
+ format_printed = 1;
+ }
+ if (r == ARCHIVE_RETRY)
+ continue;
+ if (r == ARCHIVE_EOF)
+ break;
+ p = archive_entry_pathname(entry);
+ v_print(v, "Entry %d: %s, pathname", c, errnostr(r));
+ if (p == NULL || p[0] == '\0')
+ v_print(v, " unreadable");
+ else
+ v_print(v, ": %s", p);
+ v_print(v, ", data: ");
+ if (skip_data) {
+ v_print(v, "skipping");
+ } else {
+ while ((r = archive_read_data(a, buffer, 4096) > 0))
+ ;
+ if (r == ARCHIVE_FATAL) {
+ v_print(v, "ERROR\nError string: %s\n",
+ archive_error_string(a));
+ break;
+ }
+ v_print(v, "OK");
+ }
+ v_print(v, "\n");
+ c++;
+ }
+
+ v_print(v, "Last return code: %s (%d)\n", errnostr(r), r);
+ if (r == ARCHIVE_EOF || r == ARCHIVE_OK) {
+ archive_read_free(a);
+ exit(0);
+ }
+ v_print(v, "Error string: %s\n", archive_error_string(a));
+ archive_read_free(a);
+ exit(2);
+}
diff --git a/contrib/libarchive.spec b/contrib/libarchive.spec
index f4ed3597..371ae647 100644
--- a/contrib/libarchive.spec
+++ b/contrib/libarchive.spec
@@ -1,105 +1,216 @@
-Summary: Library to create and read several different archive formats
-Name: libarchive
-Version: 3.1.2
-Release: 1
+Name: {{{ git_name }}}
+Version: {{{ git_version lead=3 follow=5 }}}
+Release: 1%{?dist}
+Summary: A library for handling streaming archive formats
+
License: BSD
-Group: Libraries
-Source0: http://libarchive.org/downloads/%{name}-%{version}.tar.gz
-URL: http:/libarchive.org/
-Requires: glibc
-Requires: zlib
-Requires: bzip2
+URL: http://www.libarchive.org/
+Source: {{{ git_pack }}}
+
+VCS: {{{ git_vcs }}}
+
+BuildRequires: automake
+BuildRequires: bison
+BuildRequires: bzip2-devel
+BuildRequires: e2fsprogs-devel
BuildRequires: gcc
-BuildRequires: gcc-c++
-BuildRequires: gawk
+BuildRequires: libacl-devel
+BuildRequires: libattr-devel
+BuildRequires: libtool
+BuildRequires: libxml2-devel
+BuildRequires: libzstd-devel
+BuildRequires: lz4-devel
+BuildRequires: lzo-devel
+BuildRequires: openssl-devel
+BuildRequires: sharutils
+BuildRequires: xz-devel
BuildRequires: zlib-devel
-BuildRequires: bzip2
-BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
-Libarchive is a programming library that can create and read several
-different streaming archive formats, including most popular TAR
-variants and several CPIO formats. It can also write SHAR archives.
+Libarchive is a programming library that can create and read several different
+streaming archive formats, including most popular tar variants, several cpio
+formats, and both BSD and GNU ar variants. It can also write shar archives and
+read ISO9660 CDROM images and ZIP archives.
+
%package devel
-Summary: Header files for libarchive library
-Group: Development/Libraries
-Requires: %{name} = %{version}-%{release}
+Summary: Development files for %{name}
+Requires: %{name}%{?_isa} = %{version}-%{release}
%description devel
-Header files for libarchive library.
-
-%package static
-Summary: Static libarchive library
-Group: Development/Libraries
-Requires: %{name}-devel = %{version}-%{release}
+The %{name}-devel package contains libraries and header files for
+developing applications that use %{name}.
-%description static
-Static libarchive library.
%package -n bsdtar
-Summary: bsdtar - tar(1) implementation based on libarchive
-Group: Applications/Archiving
-Requires: %{name} = %{version}-%{release}
+Summary: Manipulate tape archives
+Requires: %{name}%{?_isa} = %{version}-%{release}
%description -n bsdtar
-bsdtar - tar(1) implementation based on libarchive.
+The bsdtar package contains standalone bsdtar utility split off regular
+libarchive packages.
+
%package -n bsdcpio
-Summary: bsdcpio - cpio(1) implementation based on libarchive
-Group: Applications/Archiving
-Requires: %{name} = %{version}-%{release}
+Summary: Copy files to and from archives
+Requires: %{name}%{?_isa} = %{version}-%{release}
%description -n bsdcpio
-bsdcpio - cpio(1) implementation based on libarchive
+The bsdcpio package contains standalone bsdcpio utility split off regular
+libarchive packages.
+
+
+%package -n bsdcat
+Summary: Expand files to standard output
+Requires: %{name}%{?_isa} = %{version}-%{release}
+
+%description -n bsdcat
+The bsdcat program typically takes a filename as an argument or reads standard
+input when used in a pipe. In both cases decompressed data it written to
+standard output.
+
%prep
-%setup -q
+{{{ git_setup_macro }}}
+%autosetup -p1
+
%build
-mkdir -p %{buildroot}
-./configure \
---prefix=%{_prefix} \
---libexecdir=%{_libexecdir} \
---libdir=%{_libdir} \
---mandir=%{_mandir} \
---infodir=%{_infodir} \
---enable-shared=yes \
---enable-static=yes \
-| tee %{buildroot}/config.log
-make | tee %{buildroot}/make.log
+build/autogen.sh
+%configure --disable-static --without-nettle LT_SYS_LIBRARY_PATH=%_libdir
+%make_build
+
%install
-[ "%buildroot" != "/" ] && [ -d %buildroot ] && rm -rf %buildroot;
-make DESTDIR=%buildroot install
+make install DESTDIR=$RPM_BUILD_ROOT
+find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
+
+# rhbz#1294252
+replace ()
+{
+ filename=$1
+ file=`basename "$filename"`
+ binary=${file%%.*}
+ pattern=${binary##bsd}
+
+ awk "
+ # replace the topic
+ /^.Dt ${pattern^^} 1/ {
+ print \".Dt ${binary^^} 1\";
+ next;
+ }
+ # replace the first occurrence of \"$pattern\" by \"$binary\"
+ !stop && /^.Nm $pattern/ {
+ print \".Nm $binary\" ;
+ stop = 1 ;
+ next;
+ }
+ # print remaining lines
+ 1;
+ " "$filename" > "$filename.new"
+ mv "$filename".new "$filename"
+}
+
+for manpage in bsdtar.1 bsdcpio.1
+do
+ installed_manpage=`find "$RPM_BUILD_ROOT" -name "$manpage"`
+ replace "$installed_manpage"
+done
+
+
+%check
+%if %{with check}
+logfiles ()
+{
+ find -name '*_test.log' -or -name test-suite.log
+}
+
+tempdirs ()
+{
+ cat `logfiles` \
+ | awk "match(\$0, /[^[:space:]]*`date -I`[^[:space:]]*/) { print substr(\$0, RSTART, RLENGTH); }" \
+ | sort | uniq
+}
+
+cat_logs ()
+{
+ for i in `logfiles`
+ do
+ echo "=== $i ==="
+ cat "$i"
+ done
+}
+
+run_testsuite ()
+{
+ rc=0
+ %make_build check -j1 || {
+ # error happened - try to extract in koji as much info as possible
+ cat_logs
+
+ for i in `tempdirs`; do
+ if test -d "$i" ; then
+ find $i -printf "%p\n ~> a: %a\n ~> c: %c\n ~> t: %t\n ~> %s B\n"
+ cat $i/*.log
+ fi
+ done
+ return 1
+ }
+ cat_logs
+}
+
+# On a ppc/ppc64 is some race condition causing 'make check' fail on ppc
+# when both 32 and 64 builds are done in parallel on the same machine in
+# koji. Try to run once again if failed.
+%ifarch ppc
+run_testsuite || run_testsuite
+%else
+run_testsuite
+%endif
+%endif
-%clean
-rm -fr %buildroot
%files
-%{_libdir}/libarchive.so*
-
-%files static
-%{_libdir}/libarchive.a
+%{!?_licensedir:%global license %%doc}
+%license COPYING
+%doc NEWS README.md
+%{_libdir}/libarchive.so.13*
+%{_mandir}/*/cpio.*
+%{_mandir}/*/mtree.*
+%{_mandir}/*/tar.*
%files devel
-%{_libdir}/pkgconfig/libarchive.pc
-%{_libdir}/libarchive.la
%{_includedir}/*.h
-%doc %{_mandir}/man3/*
-%doc %{_mandir}/man5/*
+%{_mandir}/*/archive*
+%{_mandir}/*/libarchive*
+%{_libdir}/libarchive.so
+%{_libdir}/pkgconfig/libarchive.pc
%files -n bsdtar
-%attr(755,root,root) %{_bindir}/bsdtar
-%doc %{_mandir}/man1/bsdtar.1*
+%{!?_licensedir:%global license %%doc}
+%license COPYING
+%doc NEWS README.md
+%{_bindir}/bsdtar
+%{_mandir}/*/bsdtar*
%files -n bsdcpio
-%attr(755,root,root) %{_bindir}/bsdcpio
-%doc %{_mandir}/man1/bsdcpio.1*
+%{!?_licensedir:%global license %%doc}
+%license COPYING
+%doc NEWS README.md
+%{_bindir}/bsdcpio
+%{_mandir}/*/bsdcpio*
+
+%files -n bsdcat
+%{!?_licensedir:%global license %%doc}
+%license COPYING
+%doc NEWS README.md
+%{_bindir}/bsdcat
+%{_mandir}/*/bsdcat*
+
+
%changelog
-* Wed May 01 2013 Nikolai Lifanov <lifanov@mail.lifanov.com> - 3.1.2-1
-- Initial package
-- contrib/libarchive.spec by PLD team overhaul
-- Added "bsdcpio" package
-- Fixed build on x86_64 platform
+* Thu Mar 28 2019 Pavel Raiskup <praiskup@redhat.com> - 3.3.3-7
+- simplify libtool hacks
+
+{{ git_changelog }}
diff --git a/contrib/oss-fuzz/corpus.zip b/contrib/oss-fuzz/corpus.zip
new file mode 100644
index 00000000..4e9e2495
--- /dev/null
+++ b/contrib/oss-fuzz/corpus.zip
Binary files differ
diff --git a/contrib/oss-fuzz/libarchive_fuzzer.cc b/contrib/oss-fuzz/libarchive_fuzzer.cc
new file mode 100644
index 00000000..bc7f865b
--- /dev/null
+++ b/contrib/oss-fuzz/libarchive_fuzzer.cc
@@ -0,0 +1,49 @@
+#include <stddef.h>
+#include <stdint.h>
+#include <vector>
+
+#include "archive.h"
+
+struct Buffer {
+ const uint8_t *buf;
+ size_t len;
+};
+
+ssize_t reader_callback(struct archive *a, void *client_data,
+ const void **block) {
+ Buffer *buffer = reinterpret_cast<Buffer *>(client_data);
+ *block = buffer->buf;
+ ssize_t len = buffer->len;
+ buffer->len = 0;
+ return len;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
+ int ret;
+ ssize_t r;
+ struct archive *a = archive_read_new();
+
+ archive_read_support_filter_all(a);
+ archive_read_support_format_all(a);
+
+ Buffer buffer = {buf, len};
+ archive_read_open(a, &buffer, NULL, reader_callback, NULL);
+
+ std::vector<uint8_t> data_buffer(getpagesize(), 0);
+ struct archive_entry *entry;
+ while(1) {
+ ret = archive_read_next_header(a, &entry);
+ if (ret == ARCHIVE_EOF || ret == ARCHIVE_FATAL)
+ break;
+ if (ret == ARCHIVE_RETRY)
+ continue;
+ while ((r = archive_read_data(a, data_buffer.data(),
+ data_buffer.size())) > 0)
+ ;
+ if (r == ARCHIVE_FATAL)
+ break;
+ }
+
+ archive_read_free(a);
+ return 0;
+}
diff --git a/contrib/oss-fuzz/oss-fuzz-build.sh b/contrib/oss-fuzz/oss-fuzz-build.sh
new file mode 100755
index 00000000..83d8470b
--- /dev/null
+++ b/contrib/oss-fuzz/oss-fuzz-build.sh
@@ -0,0 +1,16 @@
+# build the project
+./build/autogen.sh
+./configure
+make -j$(nproc) all
+
+# build seed
+cp $SRC/libarchive/contrib/oss-fuzz/corpus.zip\
+ $OUT/libarchive_fuzzer_seed_corpus.zip
+
+# build fuzzer(s)
+$CXX $CXXFLAGS -Ilibarchive \
+ $SRC/libarchive/contrib/oss-fuzz/libarchive_fuzzer.cc \
+ -o $OUT/libarchive_fuzzer $LIB_FUZZING_ENGINE \
+ .libs/libarchive.a -Wl,-Bstatic -lbz2 -llzo2 \
+ -lxml2 -llzma -lz -lcrypto -llz4 -licuuc \
+ -licudata -Wl,-Bdynamic
diff --git a/contrib/shar/shar.1 b/contrib/shar/shar.1
index e3152f29..31561978 100644
--- a/contrib/shar/shar.1
+++ b/contrib/shar/shar.1
@@ -61,7 +61,8 @@ or
The following options are available:
.Bl -tag -width indent
.It Fl b
-Use an alternative binary format. Content of files will be uuencoded.
+Use an alternative binary format.
+Content of files will be uuencoded.
This option should be used to archive binary files correctly.
In this mode also file permissions will be stored to the archive.
uudecode(1) is needed to extract archives created with this option.
@@ -72,8 +73,8 @@ Redirect output to
If
.Ar file
given on command line is a directory the entire subtree will be archived.
-Symbolic links given on command line are followed. Other symbolic links will
-be archived as such.
+Symbolic links given on command line are followed.
+Other symbolic links will be archived as such.
.El
.Sh EXAMPLES
To create a shell archive of the program
@@ -111,7 +112,9 @@ The
command makes no provisions for hard links.
.Pp
Files containing magic characters or files without a newline ('\\n') as the
-last character are not handled correctly with the default format. Use the -b
+last character are not handled correctly with the default format.
+Use the
+.Fl b
option for binary files.
.Pp
It is easy to insert trojan horses into
diff --git a/contrib/shar/shar.c b/contrib/shar/shar.c
index 6d5c206e..63161fc9 100644
--- a/contrib/shar/shar.c
+++ b/contrib/shar/shar.c
@@ -170,7 +170,7 @@ out:
}
/*
- * Write singe path to the archive. The path can be a regular file, directory
+ * Write single path to the archive. The path can be a regular file, directory
* or device. Symbolic links are followed.
*/
static int