From 8520c1359e58773c569ea1ad692fa93a0e369535 Mon Sep 17 00:00:00 2001 From: d33tah Date: Wed, 10 Jul 2013 15:10:35 +0000 Subject: [PATCH] restore default SIGPIPE handler in netexec child process. --- ncat/ncat_posix.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ncat/ncat_posix.c b/ncat/ncat_posix.c index 2a1758714..314776d7c 100644 --- a/ncat/ncat_posix.c +++ b/ncat/ncat_posix.c @@ -180,6 +180,14 @@ void netexec(struct fdinfo *info, char *cmdexec) close(child_stdin[1]); close(child_stdout[0]); + /* We might have turned off SIGPIPE handling in ncat_listen.c. Since + the child process SIGPIPE might mean that the connection got broken, + ignoring it could result in an infinite loop if the code here + ignores the error codes of read()/write() calls. So, just in case, + let's restore SIGPIPE so that writing to a broken pipe results in + killing the child process. */ + Signal(SIGPIPE, SIG_DFL); + /* rearrange stdin and stdout */ Dup2(child_stdin[0], STDIN_FILENO); Dup2(child_stdout[1], STDOUT_FILENO);