From 36bac92cd2ef4a8719f62de9b4bde659a8682463 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 2 Jun 2025 23:29:49 +0200 Subject: [PATCH] tools: Enforce default handling of SIGCHLD Ignoring SIGCHLD gets passed to child processes. Doing that has influence on waitpid, namely that zombie processes won't be created. This means that a status can never be read. We can't enforce this in library, but libarchive's tools can be protected against this by enforcing default handling. Signed-off-by: Tobias Stoeckmann --- cat/bsdcat.c | 13 +++++++++++++ cpio/cpio.c | 12 ++++++++++-- tar/bsdtar.c | 5 +++++ unzip/bsdunzip.c | 13 +++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/cat/bsdcat.c b/cat/bsdcat.c index 731621fa9..40fdd0436 100644 --- a/cat/bsdcat.c +++ b/cat/bsdcat.c @@ -7,6 +7,9 @@ #include "bsdcat_platform.h" +#ifdef HAVE_SIGNAL_H +#include +#endif #include #ifdef HAVE_STDLIB_H #include @@ -105,6 +108,16 @@ main(int argc, char **argv) bsdcat = &bsdcat_storage; memset(bsdcat, 0, sizeof(*bsdcat)); +#if defined(HAVE_SIGACTION) && defined(SIGCHLD) + { /* Do not ignore SIGCHLD. */ + struct sigaction sa; + sa.sa_handler = SIG_DFL; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGCHLD, &sa, NULL); + } +#endif + lafe_setprogname(*argv, "bsdcat"); bsdcat->argv = argv; diff --git a/cpio/cpio.c b/cpio/cpio.c index 2bf1bfa29..cd88d416e 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -124,13 +124,21 @@ main(int argc, char *argv[]) cpio->buff_size = sizeof(buff); -#if defined(HAVE_SIGACTION) && defined(SIGPIPE) - { /* Ignore SIGPIPE signals. */ +#if defined(HAVE_SIGACTION) + { struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; +#ifdef SIGPIPE + /* Ignore SIGPIPE signals. */ sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, NULL); +#endif +#ifdef SIGCHLD + /* Do not ignore SIGCHLD. */ + sa.sa_handler = SIG_DFL; + sigaction(SIGCHLD, &sa, NULL); +#endif } #endif diff --git a/tar/bsdtar.c b/tar/bsdtar.c index 53ac135f0..c80c1a1b6 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -182,6 +182,11 @@ main(int argc, char **argv) /* Ignore SIGPIPE signals. */ sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, NULL); +#endif +#ifdef SIGCHLD + /* Do not ignore SIGCHLD. */ + sa.sa_handler = SIG_DFL; + sigaction(SIGCHLD, &sa, NULL); #endif } #endif diff --git a/unzip/bsdunzip.c b/unzip/bsdunzip.c index 621afbeb9..0559a0ddc 100644 --- a/unzip/bsdunzip.c +++ b/unzip/bsdunzip.c @@ -29,6 +29,9 @@ #ifdef HAVE_LOCALE_H #include #endif +#ifdef HAVE_SIGNAL_H +#include +#endif #ifdef HAVE_STDARG_H #include #endif @@ -1187,6 +1190,16 @@ main(int argc, char *argv[]) const char *zipfile; int nopts; +#if defined(HAVE_SIGACTION) && defined(SIGCHLD) + { /* Do not ignore SIGCHLD. */ + struct sigaction sa; + sa.sa_handler = SIG_DFL; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGCHLD, &sa, NULL); + } +#endif + lafe_setprogname(*argv, "bsdunzip"); #if HAVE_SETLOCALE -- 2.47.2