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

Prevent MsgHdr::with_control with empty buffer causes error in macOS #507

Closed
wants to merge 1 commit into from

Conversation

youknowone
Copy link

@youknowone youknowone commented Apr 22, 2024

Otherwise panic when cfg(debug_assertions) will be another good prevention.

Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

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

Are there valid reasons to send an empty control value? Or is this always programmer error?

@youknowone
Copy link
Author

To tell about the valid reasons, I am not familiar with low level socket API that much.
At least it was a programmer error for my case. Is panic better?

@Thomasdezeeuw
Copy link
Collaborator

To tell about the valid reasons, I am not familiar with low level socket API that much. At least it was a programmer error for my case. Is panic better?

No, I would say not doing anything would be better. We're not going to introduce panics in our API, but hiding errors/problematic code is also not something we want.

@youknowone
Copy link
Author

youknowone commented Apr 22, 2024

It was a small glitch but painful to debug.
I finally could find the buffer is wrong, but it was hidden inside socket2 crate.
As a library user, I could see something goes wrong on sendmsg but not on with_control. If with_control is not expected to be called with empty buffer by nature, it could be warned at the moment, instead of deferring it.
Maybe the other side of the reason is Debug for MsgHdr was useless to look in it and didn't display its contents. The combination of blackboxed MsgHdr and deferred error took me long time to look around control_buffer.

I changed the patch to debug_assert!() make it neither panic(in real use) nor hiding and deferring error. Please take a review if you agree it is a UX caveat.

@Thomasdezeeuw
Copy link
Collaborator

It was a small glitch but painful to debug. I finally could find the buffer is wrong, but it was hidden inside socket2 crate.

Socket2 doesn't hide anything, you pass it an invalid buffer, it will pass that buffer along to the OS.

As a library user, I could see something goes wrong on sendmsg but not on with_control. If with_control is not expected to be called with empty buffer by nature, it could be warned at the moment, instead of deferring it. Maybe the other side of the reason is Debug for MsgHdr was useless to look in it and didn't display its contents. The combination of blackboxed MsgHdr and deferred error took me long time to look around control_buffer.

The layout of MsgHdr depends on the underlying OS, it's not a black box.

I changed the patch to debug_assert!() make it neither panic(in real use) nor hiding and deferring error. Please take a review if you agree it is a UX caveat.

Socket2 is just wrapper around the OS interfaces, so I don't think this fits in socket2.

@youknowone
Copy link
Author

I understand your concern. Is there any plan to implement better Debug for MagHdr in that case? Debug can be platform-specific implementation and it will not affect any actual behavior. Minor platforms still can use current implementation

@Thomasdezeeuw
Copy link
Collaborator

I understand your concern. Is there any plan to implement better Debug for MagHdr in that case? Debug can be platform-specific implementation and it will not affect any actual behavior. Minor platforms still can use current implementation

A pr for that would be accepted.

@Thomasdezeeuw
Copy link
Collaborator

Closing this since I still don't think it's something we want.

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