summaryrefslogtreecommitdiff
path: root/lib/pipe.c
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-07-17 12:00:07 -0600
committerEric Blake <ebb9@byu.net>2009-07-17 13:06:31 -0600
commitfdccb1c31b8693bcda4faea73b0d81d1c3be0719 (patch)
tree9f26042fa957c999e8ad4b0322869733931b0dbb /lib/pipe.c
parentfeb2268308fe0aa483e9614c714cd66480ba033e (diff)
downloadgnulib-fdccb1c31b8693bcda4faea73b0d81d1c3be0719.tar.gz
pipe: be robust in face of closed fds
* lib/pipe.c (create_pipe): Closed standard descriptors in parent should cause child to misbehave. * modules/pipe-tests: New module. * tests/test-pipe.c: New file. * tests/test-pipe.sh: New file. Reported by Akim Demaille. Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'lib/pipe.c')
-rw-r--r--lib/pipe.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/pipe.c b/lib/pipe.c
index f8e7dee104..64fa6a2473 100644
--- a/lib/pipe.c
+++ b/lib/pipe.c
@@ -134,10 +134,12 @@ create_pipe (const char *progname,
if (pipe_stdout)
if (_pipe (ifd, 4096, O_BINARY | O_NOINHERIT) < 0
- || (ifd[0] = fd_safer (ifd[0])) < 0)
+ || (ifd[0] = fd_safer (ifd[0])) < 0
+ || (ifd[1] = fd_safer (ifd[1])) < 0)
error (EXIT_FAILURE, errno, _("cannot create pipe"));
if (pipe_stdin)
if (_pipe (ofd, 4096, O_BINARY | O_NOINHERIT) < 0
+ || (ofd[0] = fd_safer (ofd[0])) < 0
|| (ofd[1] = fd_safer (ofd[1])) < 0)
error (EXIT_FAILURE, errno, _("cannot create pipe"));
/* Data flow diagram:
@@ -258,12 +260,10 @@ create_pipe (const char *progname,
pid_t child;
if (pipe_stdout)
- if (pipe (ifd) < 0
- || (ifd[0] = fd_safer (ifd[0])) < 0)
+ if (pipe_safer (ifd) < 0)
error (EXIT_FAILURE, errno, _("cannot create pipe"));
if (pipe_stdin)
- if (pipe (ofd) < 0
- || (ofd[1] = fd_safer (ofd[1])) < 0)
+ if (pipe_safer (ofd) < 0)
error (EXIT_FAILURE, errno, _("cannot create pipe"));
/* Data flow diagram:
*