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

Undefined behavior: CMSG_DATA and CMSG_NXTHDR may return null #12

Closed
Manishearth opened this issue Aug 11, 2023 · 2 comments
Closed

Undefined behavior: CMSG_DATA and CMSG_NXTHDR may return null #12

Manishearth opened this issue Aug 11, 2023 · 2 comments

Comments

@Manishearth
Copy link
Contributor

*(CMSG_DATA(header) as *mut c_void as *mut _) = creds;

let dst = CMSG_DATA(header) as *mut c_void;

let first_fd = CMSG_DATA(self.next_message) as *const c_void;

let creds_ptr = CMSG_DATA(self.next_message) as *const c_void;

header = &mut*CMSG_NXTHDR(&mut msg, header);

The docs say that these functions may return null, but they're not null-checked in the locations above (the usage of CMSG_NXTHDR for initializing next_message is, however). The code is dereferencing the results here and dereferencing a null pointer is UB: it should null-check these.

@tormol
Copy link
Owner

tormol commented Aug 14, 2023

As far as I understand they'll only return null if there's not enough space.
The code tries to calculate and allocate the required space, so it should never happen.

But assertions have been added in #8, and has now been released in 0.2.7 and 0.3.0.
And there was a bug in the space calculation, which is also fixed in those versions.

@tormol tormol closed this as completed Aug 14, 2023
@Manishearth
Copy link
Contributor Author

Hmm, okay, makes sense. Thanks!

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

No branches or pull requests

2 participants