]> granicus.if.org Git - sudo/commitdiff
when setting up pipes in child process check for case where stdin == pipe fd 0
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 16 Oct 2001 05:35:26 +0000 (05:35 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 16 Oct 2001 05:35:26 +0000 (05:35 +0000)
logging.c

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