]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Mask SIGPIPE for libarchive test, tar, and cpio.
authorTim Kientzle <kientzle@gmail.com>
Sat, 5 Nov 2011 23:34:57 +0000 (19:34 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sat, 5 Nov 2011 23:34:57 +0000 (19:34 -0400)
As reported at:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=641265

The SIGPIPE occurs when feeding data through a decompression
program; the external program may see an end-of-data marker
and exit before we've finished feeding it all of the data.
(This happens when the data has garbage padding at the end.)
We want to catch and ignore the EPIPE since we can still
read the data coming out of the decompression program.

SVN-Revision: 3751

cpio/cpio.c
libarchive/test/main.c
tar/bsdtar.c

index 6a09412c4705e593d759feee70b6f841688e9241..ff5a1c600ace8bf06cac7c9f9aa4442697a5d0dd 100644 (file)
@@ -56,6 +56,9 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/cpio.c,v 1.15 2008/12/06 07:30:40 kientzle
 #ifdef HAVE_PWD_H
 #include <pwd.h>
 #endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
 #ifdef HAVE_STDARG_H
 #include <stdarg.h>
 #endif
@@ -136,6 +139,16 @@ main(int argc, char *argv[])
        cpio->buff = buff;
        cpio->buff_size = sizeof(buff);
 
+#if defined(HAVE_SIGACTION) && defined(SIGPIPE)
+       { /* Ignore SIGPIPE signals. */
+               struct sigaction sa;
+               sigemptyset(&sa.sa_mask);
+               sa.sa_flags = 0;
+               sa.sa_handler = SIG_IGN;
+               sigaction(SIGPIPE, &sa, NULL);
+       }
+#endif
+
        /* Need lafe_progname before calling lafe_warnc. */
        if (*argv == NULL)
                lafe_progname = "bsdcpio";
index 18ea1dbc5511c68aea74a6060fac766e853b893a..94fa77094d6d33f87c4739bed41e0ad7c26ffd60 100644 (file)
@@ -33,6 +33,9 @@
 #endif
 #include <limits.h>
 #include <locale.h>
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
 #include <stdarg.h>
 #include <time.h>
 
@@ -2342,6 +2345,16 @@ main(int argc, char **argv)
        }
 #endif
 
+#if !defined(_WIN32) && defined(SIGPIPE)
+       {   /* Ignore SIGPIPE signals */
+               struct sigaction sa;
+               sa.sa_handler = SIG_IGN;
+               sigemptyset(&sa.sa_mask);
+               sa.sa_flags = 0;
+               sigaction(SIGPIPE, &sa, NULL);
+       }
+#endif
+
        /*
         * Create a temp directory for the following tests.
         * Include the time the tests started as part of the name,
index 6576b2f08fad39854ff0b7e64bfd1614d6fb0f9a..a55b7dcf0f98a0ecfd9bf28004e4c7c40cbfb504 100644 (file)
@@ -153,8 +153,8 @@ main(int argc, char **argv)
        bsdtar->uid = -1;
        option_o = 0;
 
-#if defined(HAVE_SIGACTION) && (defined(SIGINFO) || defined(SIGUSR1))
-       { /* Catch SIGINFO and SIGUSR1, if they exist. */
+#if defined(HAVE_SIGACTION)
+       { /* Set up signal handling. */
                struct sigaction sa;
                sa.sa_handler = siginfo_handler;
                sigemptyset(&sa.sa_mask);
@@ -167,6 +167,11 @@ main(int argc, char **argv)
                /* ... and treat SIGUSR1 the same way as SIGINFO. */
                if (sigaction(SIGUSR1, &sa, NULL))
                        lafe_errc(1, errno, "sigaction(SIGUSR1) failed");
+#endif
+#ifdef SIGPIPE
+               /* Ignore SIGPIPE signals. */
+               sa.sa_handler = SIG_IGN;
+               sigaction(SIGPIPE, &sa, NULL);
 #endif
        }
 #endif