Check for dup2() failure.

This commit is contained in:
Todd C. Miller
2010-06-15 09:02:23 -04:00
parent 59718c32e4
commit c2f8d24f20
5 changed files with 40 additions and 28 deletions

View File

@@ -463,7 +463,7 @@ send_mail(const char *fmt, ...)
}
# endif
#endif
chdir("/");
(void) chdir("/");
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0644)) != -1) {
(void) dup2(fd, STDIN_FILENO);
(void) dup2(fd, STDOUT_FILENO);
@@ -501,12 +501,15 @@ send_mail(const char *fmt, ...)
/* Child, set stdin to output side of the pipe */
if (pfd[0] != STDIN_FILENO) {
(void) dup2(pfd[0], STDIN_FILENO);
if (dup2(pfd[0], STDIN_FILENO) != -1) {
mysyslog(LOG_ERR, "cannot dup stdin: %m");
_exit(127);
}
(void) close(pfd[0]);
}
(void) close(pfd[1]);
/* Build up an argv based the mailer path and flags */
/* Build up an argv based on the mailer path and flags */
mflags = estrdup(def_mailerflags);
mpath = estrdup(def_mailerpath);
if ((argv[0] = strrchr(mpath, ' ')))