From d98646e43096053ee13f5a9a6af38f8c723b1aaf Mon Sep 17 00:00:00 2001 From: Ross Lagerwall Date: Wed, 27 Jul 2011 07:16:31 +0200 Subject: Issue #12607: In subprocess, fix issue where if stdin, stdout or stderr is given as a low fd, it gets overwritten. --- Modules/_posixsubprocess.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Modules/_posixsubprocess.c') diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index bf10cbb43e..11b24a031f 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -69,6 +69,13 @@ static void child_exec(char *const exec_array[], } POSIX_CALL(close(errpipe_read)); + /* When duping fds, if there arises a situation where one of the fds is + either 0, 1 or 2, it is possible that it is overwritten (#12607). */ + if (c2pwrite == 0) + POSIX_CALL(c2pwrite = dup(c2pwrite)); + if (errwrite == 0 || errwrite == 1) + POSIX_CALL(errwrite = dup(errwrite)); + /* Dup fds for child. dup2() removes the CLOEXEC flag but we must do it ourselves if dup2() would be a no-op (issue #10806). */ -- cgit v1.2.1