summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-08 21:08:29 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-08 21:08:29 -0400
commit94edd38e1d2559f6685629eba71669ab24023c5d (patch)
tree3ec28b85ba7623bca325b595b4802371c130c68e
parentedfd706d9cb85a1195b6b575468db90744e13a6e (diff)
basic/util: check return value of dup2 in fork_agent()
CID #1304689.
-rw-r--r--src/basic/util.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index ea1bed7ceb..f1e3bd5b48 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -419,13 +419,17 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa
_exit(EXIT_FAILURE);
}
- if (!stdout_is_tty)
- dup2(fd, STDOUT_FILENO);
+ if (!stdout_is_tty && dup2(fd, STDOUT_FILENO) < 0) {
+ log_error_errno(errno, "Failed to dup2 /dev/tty: %m");
+ _exit(EXIT_FAILURE);
+ }
- if (!stderr_is_tty)
- dup2(fd, STDERR_FILENO);
+ if (!stderr_is_tty && dup2(fd, STDERR_FILENO) < 0) {
+ log_error_errno(errno, "Failed to dup2 /dev/tty: %m");
+ _exit(EXIT_FAILURE);
+ }
- if (fd > 2)
+ if (fd > STDERR_FILENO)
close(fd);
}