-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
os.forkpty() and pty.fork() return FD with O_CLOEXEC #139184
Copy link
Copy link
Open
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Metadata
Metadata
Assignees
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Fields
Give feedbackNo fields configured for issues without a type.
Bug report
Bug description:
https://docs.python.org/3/library/os.html#os.forkpty
https://docs.python.org/3/library/pty.html#pty.fork
Say nothing about that.
Lib/pty.py:
Also uses
openpty()which also does not set O_CLOEXECMeanwhile, there is a C function
posix_openpt(int flags);which allows setting O_CLOEXEC.Seems, fd-leak safe solution is to boilerplate all the actions by hand. i.e. same way as
pty.fork()does, but also implementopenpty()usingposix_openpt()+ptsname()/ptsname_r().Just setting O_CLOEXEC after
openpty()or after calling Cforkpty()is not enough because of race-condition and possible file descriptor leak.So, CLOEXEC behavior should be documented and race-condition prevented
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs