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

Fixes recvm(m)sg blindly assuming correct initialization of received address #2249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jan561
Copy link
Contributor

@Jan561 Jan561 commented Dec 3, 2023

recvm(m)sg now calling SockaddrLike::from_raw instead of assume_init on the received address

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

@Jan561
Copy link
Contributor Author

Jan561 commented Dec 3, 2023

Always fucking apple

@Jan561 Jan561 force-pushed the recv_from_raw branch 2 times, most recently from dd5bf36 to 12bf2c7 Compare December 3, 2023 18:19
@Jan561 Jan561 changed the title Fix recvm(m)sg blindly assuming correct initialization of received address Fixes recvm(m)sg blindly assuming correct initialization of received address Dec 3, 2023
let addr_len = mhdr.msg_namelen;

let address = unsafe {
S::from_raw(address.as_ptr().cast(), Some(addr_len))
Copy link
Member

Choose a reason for hiding this comment

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

Are you aware that this creates a data copy? The original code was carefully designed to avoid such a thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it creates a copy, but so does recvfrom (currently, on the master branch):

Ok((ret, T::from_raw(addr.assume_init().as_ptr(), Some(len))))

I feel like in a future PR we should make the address field of RecvMsg private and instead add a getter that lazily performs the checks and the copy, like this:

pub fn address(&self) -> Option<S> {
    S::from_raw(self.address.as_ptr(), len)
}

Copy link
Member

Choose a reason for hiding this comment

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

Why does it matter that some other function also performs a data copy? Are you pointing that out to suggest that we improve it? I'm requesting that you not add an additional data copy to recvmsg.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay yeah, that makes sense, I think I misunderstood you before. I'll change the signature of read_mhdr back to expecting a pointer, and perform the conversion there.

let addr_len = mhdr.msg_namelen;

let address = unsafe {
S::from_raw(address.as_ptr().cast(), Some(addr_len))
Copy link
Member

Choose a reason for hiding this comment

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

Why does it matter that some other function also performs a data copy? Are you pointing that out to suggest that we improve it? I'm requesting that you not add an additional data copy to recvmsg.

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