From 62b0c6727235a0bc560179dbf6b13d252716c02c Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Sat, 21 Feb 2015 11:38:18 +0100 Subject: [PATCH] remove longjmp in signalhandler of slocal To avoid undefined behavior kill the child process in the signal handler and set an interrupt flag. --- h/rcvmail.h | 1 - uip/slocal.c | 23 +++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/h/rcvmail.h b/h/rcvmail.h index 6a62284..4a282fc 100644 --- a/h/rcvmail.h +++ b/h/rcvmail.h @@ -4,7 +4,6 @@ # include # include -# include # include # include diff --git a/uip/slocal.c b/uip/slocal.c index ff8df8c..cf9a9b0 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -90,7 +90,8 @@ static struct passwd *pw; /* passwd file entry */ static char ddate[BUFSIZ]; /* record the delivery date */ struct tws *now; -static jmp_buf myctx; +volatile sig_atomic_t eflag = 0; /* flag to indecate interrupt */ +static pid_t child_id; /* flags for pair->p_flags */ #define P_NIL 0x00 @@ -1034,16 +1035,6 @@ usr_pipe(int fd, char *cmd, char *pgm, char **vec, int suppress) default: /* parent process */ - if (setjmp(myctx)) { - /* - ** Ruthlessly kill the child and anything - ** else in its process group. - */ - kill(-child_id, SIGKILL); - if (verbose) - verbose_printf(", timed-out; terminated\n"); - return -1; - } SIGNAL(SIGALRM, alrmser); bytes = fstat(fd, &st) != -1 ? (int) st.st_size : 100; @@ -1061,6 +1052,13 @@ usr_pipe(int fd, char *cmd, char *pgm, char **vec, int suppress) status = pidwait(child_id, 0); alarm(0); + if (eflag) { + if (verbose) { + verbose_printf(", timed-out; terminated\n"); + } + return -1; + } + if (verbose) { if (!status) { verbose_printf(", success.\n"); @@ -1078,7 +1076,8 @@ usr_pipe(int fd, char *cmd, char *pgm, char **vec, int suppress) static void alrmser(int i) { - longjmp(myctx, DONE); + eflag = 1; + kill(-child_id, SIGKILL); } -- 1.7.10.4