Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.1 Do not leak file descriptors #35

Merged
merged 1 commit into from
Jul 14, 2024
Merged

Conversation

lhchavez
Copy link
Contributor

The openpty function was created on a simpler time, when O_CLOEXEC was not even a thing. Leaking file descriptors was fine. But we don't live in that world anymore.

This change now marks both ends of the PTY as close-on-exec, so that the file descriptors are not leaked. Importantly, since we rely on both copies (the one in ruspty and the one in the child) being closed to consider the stream done, if we manage to leak the FD to another shell, there will be an unexpected third copy, so the stream will unnecessarily hang for a second (good that we added a failsafe cap on execution time)!

The `openpty` function was created on a simpler time, when `O_CLOEXEC`
was not even a thing. Leaking file descriptors was _fine_. But we don't
live in that world anymore.

This change now marks both ends of the PTY as close-on-exec, so that the
file descriptors are not leaked. Importantly, since we rely on both
copies (the one in ruspty and the one in the child) being closed to
consider the stream done, _if_ we manage to leak the FD to another
shell, there will be an unexpected third copy, so the stream will
unnecessarily hang for a second (good that we added a failsafe cap on
execution time)!
@lhchavez lhchavez force-pushed the lh-do-not-leak-file-descriptors branch from 5e373e2 to 6266661 Compare July 14, 2024 02:46
@lhchavez lhchavez merged commit 6acb8f2 into main Jul 14, 2024
4 checks passed
@lhchavez lhchavez deleted the lh-do-not-leak-file-descriptors branch July 14, 2024 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants