about summary refs log tree commit diff
path: root/src/pipe-tools
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2021-02-11 17:38:53 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2021-02-11 17:38:53 +0000
commitc0e09dfe5ff3630f914f1008941a1cfdacbd3db2 (patch)
treefbd1629012b6c6d1ec11c32b8010814616e6eae8 /src/pipe-tools
parent4d157070b438574bb7c5c30cb62a135f056b4289 (diff)
downloads6-c0e09dfe5ff3630f914f1008941a1cfdacbd3db2.tar.gz
s6-c0e09dfe5ff3630f914f1008941a1cfdacbd3db2.tar.xz
s6-c0e09dfe5ff3630f914f1008941a1cfdacbd3db2.zip
bugfix: unignore SIGPIPE before execing a user-controlled process
Diffstat (limited to 'src/pipe-tools')
-rw-r--r--src/pipe-tools/s6-ftrig-listen.c4
-rw-r--r--src/pipe-tools/s6-ftrig-listen1.c7
2 files changed, 8 insertions, 3 deletions
diff --git a/src/pipe-tools/s6-ftrig-listen.c b/src/pipe-tools/s6-ftrig-listen.c
index d9c4b53..c6c105f 100644
--- a/src/pipe-tools/s6-ftrig-listen.c
+++ b/src/pipe-tools/s6-ftrig-listen.c
@@ -66,7 +66,7 @@ int main (int argc, char const **argv, char const *const *envp)
   x[0].fd = selfpipe_init() ;
   if (x[0].fd < 0) strerr_diefu1sys(111, "selfpipe_init") ;
   if (selfpipe_trap(SIGCHLD) < 0) strerr_diefu1sys(111, "selfpipe_trap") ;
-  if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "sig_ignore") ;
+  if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ;
 
   if (!ftrigr_startf_g(&a, &deadline)) strerr_diefu1sys(111, "ftrigr_startf") ;
   x[1].fd = ftrigr_fd(&a) ;
@@ -81,8 +81,10 @@ int main (int argc, char const **argv, char const *const *envp)
       if (!ids[i]) strerr_diefu4sys(111, "subscribe to ", argv[i<<1], " with regexp ", argv[(i<<1)+1]) ;
     }
 
+    sig_restore(SIGPIPE) ;
     pid = child_spawn0(argv[argc1 + 1], argv + argc1 + 1, envp) ;
     if (!pid) strerr_diefu2sys(111, "spawn ", argv[argc1 + 1]) ;
+    if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ;
 
     for (;;)
     {
diff --git a/src/pipe-tools/s6-ftrig-listen1.c b/src/pipe-tools/s6-ftrig-listen1.c
index b04808c..ecb7593 100644
--- a/src/pipe-tools/s6-ftrig-listen1.c
+++ b/src/pipe-tools/s6-ftrig-listen1.c
@@ -4,6 +4,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <unistd.h>
+
 #include <skalibs/sgetopt.h>
 #include <skalibs/types.h>
 #include <skalibs/allreadwrite.h>
@@ -13,6 +14,7 @@
 #include <skalibs/djbunix.h>
 #include <skalibs/sig.h>
 #include <skalibs/selfpipe.h>
+
 #include <s6/ftrigr.h>
 
 #define USAGE "s6-ftrig-listen1 [ -t timeout ] fifodir regexp prog..."
@@ -57,7 +59,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
 
   tain_now_set_stopwatch_g() ;
   tain_add_g(&deadline, &tto) ;
-
+  if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "sig_ignore") ;
   if (!ftrigr_startf_g(&a, &deadline)) strerr_diefu1sys(111, "ftrigr_startf") ;
   id = ftrigr_subscribe_g(&a, argv[0], argv[1], 0, &deadline) ;
   if (!id) strerr_diefu4sys(111, "subscribe to ", argv[0], " with regexp ", argv[1]) ;
@@ -65,11 +67,12 @@ int main (int argc, char const *const *argv, char const *const *envp)
   x[0].fd = selfpipe_init() ;
   if (x[0].fd < 0) strerr_diefu1sys(111, "selfpipe_init") ;
   if (selfpipe_trap(SIGCHLD) < 0) strerr_diefu1sys(111, "selfpipe_trap") ;
-  if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "sig_ignore") ;
   x[1].fd = ftrigr_fd(&a) ;
 
+  sig_restore(SIGPIPE) ;
   pid = child_spawn0(argv[2], argv+2, envp) ;
   if (!pid) strerr_diefu2sys(111, "spawn ", argv[2]) ;
+  if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "sig_ignore") ;
 
   for (;;)
   {