when setting up pipes in child process check for case where stdin == pipe fd 0

This commit is contained in:
Todd C. Miller
2001-10-16 05:35:26 +00:00
parent d6e0c7049e
commit 1fbc786d66

View File

@@ -469,10 +469,12 @@ send_mail(line)
char *mpath, *mflags; char *mpath, *mflags;
int i; int i;
/* Child. */ /* Child, set stdin to output side of the pipe */
(void) close(pfd[1]); if (pfd[0] != STDIN_FILENO) {
(void) dup2(pfd[0], STDIN_FILENO); (void) dup2(pfd[0], STDIN_FILENO);
(void) close(pfd[0]); (void) close(pfd[0]);
}
(void) close(pfd[1]);
/* Build up an argv based the mailer path and flags */ /* Build up an argv based the mailer path and flags */
mflags = estrdup(def_str(I_MAILERFLAGS)); mflags = estrdup(def_str(I_MAILERFLAGS));
@@ -501,8 +503,8 @@ send_mail(line)
break; break;
} }
mail = fdopen(pfd[1], "w");
(void) close(pfd[0]); (void) close(pfd[0]);
mail = fdopen(pfd[1], "w");
/* Pipes are all setup, send message via sendmail. */ /* Pipes are all setup, send message via sendmail. */
(void) fprintf(mail, "To: %s\nFrom: %s\nSubject: ", (void) fprintf(mail, "To: %s\nFrom: %s\nSubject: ",