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

Add non-NULL asserts to CMSG_* returns, null-initialize AncillaryBuf #8

Merged
merged 1 commit into from
Aug 12, 2023

Conversation

domenukk
Copy link
Contributor

@domenukk domenukk commented Aug 7, 2023

Added two checks for NULL returns and one zero-ing that is technically more correct

Copy link
Owner

@tormol tormol left a comment

Choose a reason for hiding this comment

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

Would be nice to describe the changes in the commit message in addition to the PR.

I see CMSG_NXTHDR() requires the buffer to be zero-initialized, so that's a good catch.

src/ancillary.rs Outdated
@@ -119,14 +119,29 @@ pub fn send_ancillary(
}

#[cfg(not(any(target_os="illumos", target_os="solaris")))] {
let mut header = &mut*CMSG_FIRSTHDR(&mut msg);
let header_ptr = CMSG_FIRSTHDR(&mut msg);
if header_ptr.is_null() {
Copy link
Owner

Choose a reason for hiding this comment

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

This can only happen as result of a bug, so an assert or debug_assert would be better.

Speaking of bugs, I see CMSG_SPACE() not CMSG_LEN() should be used to calculate the size, so this could happen. But I can fix that.

src/ancillary.rs Show resolved Hide resolved
@tormol
Copy link
Owner

tormol commented Aug 7, 2023

I've fixed the CI failure, please rebase.

@domenukk domenukk changed the title Safer unsafe handling Added non-NULL asserts to CMSG_* returns Aug 8, 2023
@domenukk
Copy link
Contributor Author

domenukk commented Aug 8, 2023

Rebased and switched to assert

@domenukk domenukk changed the title Added non-NULL asserts to CMSG_* returns Add non-NULL asserts to CMSG_* returns, null-initialize AncillaryBuf Aug 8, 2023
@tormol tormol merged commit 6fca0fb into tormol:master Aug 12, 2023
6 checks passed
@tormol
Copy link
Owner

tormol commented Aug 12, 2023

Thanks!

tormol pushed a commit that referenced this pull request Aug 13, 2023
CMSG_FIRSTHDR() and CMSG_NXTHDR() expect the buffer to be zero-initialized.

Also assert that these functions don't return NULL
@tormol
Copy link
Owner

tormol commented Aug 14, 2023

Released as 0.2.7 and 0.3.0.

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.

None yet

2 participants