Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
On Windows, do not use inheritable file descriptors to wrap handles in
:func:`os.pipe`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind to also document _io._WindowsConsoleIO.fileno() fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Victor, for looking at this PR -- I will update it soon.

6 changes: 4 additions & 2 deletions Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,11 @@ _io__WindowsConsoleIO_fileno_impl(winconsoleio *self)
if (self->fd < 0 && self->handle != INVALID_HANDLE_VALUE) {
_Py_BEGIN_SUPPRESS_IPH
if (self->writable)
self->fd = _open_osfhandle((intptr_t)self->handle, _O_WRONLY | _O_BINARY);
self->fd = _open_osfhandle((intptr_t)self->handle,
_O_WRONLY | _O_BINARY | _O_NOINHERIT);
else
self->fd = _open_osfhandle((intptr_t)self->handle, _O_RDONLY | _O_BINARY);
self->fd = _open_osfhandle((intptr_t)self->handle,
_O_RDONLY | _O_BINARY | _O_NOINHERIT);
_Py_END_SUPPRESS_IPH
}
if (self->fd < 0)
Expand Down
4 changes: 2 additions & 2 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -9200,8 +9200,8 @@ os_pipe_impl(PyObject *module)
_Py_BEGIN_SUPPRESS_IPH
ok = CreatePipe(&read, &write, &attr, 0);
if (ok) {
fds[0] = _open_osfhandle((intptr_t)read, _O_RDONLY);
fds[1] = _open_osfhandle((intptr_t)write, _O_WRONLY);
fds[0] = _open_osfhandle((intptr_t)read, _O_RDONLY | _O_NOINHERIT);
fds[1] = _open_osfhandle((intptr_t)write, _O_WRONLY | _O_NOINHERIT);
if (fds[0] == -1 || fds[1] == -1) {
CloseHandle(read);
CloseHandle(write);
Expand Down