-
Notifications
You must be signed in to change notification settings - Fork 666
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
feat: I/O safety for 'sys/termios' & 'pty' #1921
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Soon we will change nix::unistd::close to take an OwnedFd, which will make the double-close situation much harder to trigger. Given that, I'm cool with this PR. We don't need to worry overmuch about what happens in Drop
.
I think it makes sense to drop those particular trait implementations. They aren't very useful for file descriptors. PartialEq used to be, but isn't any more now that OwnedFd isn't Clone. So how would you ever get two PtyMaster objects that were equal? Equally weird, one might expect that file descriptors returned by dup2
would be equal to their originals, but they won't be for any likely implementation of PartialEq.
This PR looks pretty good. I just wonder if we should add explicit instructions about Drop to the CHANGELOG.
0fb3a12
to
8f52bc9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
What this PR does:
sys/termios
andpty
Known Problems:
Double free issue on
PtyMaster
I have changed the
RawFd
inPtyMaster
toOwnedFd
in this PR, with thischange, the double-free issue still exists, see this test code snippet
(From this comment)
I have tested this code with
nix 0.26.1
, and I am still gettingEBADF
, which means the current impl does not prevent this problem either.If we still wanna the drop of
PtyMaster
panic when the internalfd
is invalidas we did in PtyMaster::drop should panic on EBADF #677, then we have to revert the changes to use
RawFd
and manually implDrop
.Some trait implementations for some types are removed
struct OpenptyResult
:struct ForkptyResult
:struct PtyMaster
:In the previous implementation, these trait impls are
#[derive()]
ed, due tothe type change to
OwnedFd
, we can no longer derive them. Should we manuallyimplement them?
I kinda think we should at least impl
PartialEq
andEq
forOpenptyResult
and
PtyMaster
.Some Clarifications that may help code review
For the basic
fd
-related syscall likeread(2)
,write(2)
andfcntl(2)
, I am still using the old
RawFd
interfaces, as they will be covered inother PRs.
Two helper functions
write_all()
intest/sys/test_termios.rs
:read_exact()
intest/test.rs
:I have added I/O safety for them, but it actually does not matter whether
they use
Fd: AsFd
orRawFd
. So feel free to ask me to discard these changesif you guys don't like it.