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

sockaddr_storage_to_addr is documented as being more lenient with the size than it is in practice #1479

Closed
khuey opened this issue Jul 25, 2021 · 4 comments · Fixed by #1486

Comments

@khuey
Copy link
Contributor

khuey commented Jul 25, 2021

The documentation says

The len argument should be the number of bytes in the sockaddr_storage that are actually allocated and valid. It must be at least as large as all the useful parts of the structure.

This suggests that passing in a size larger than what is actually used (say, size_of::<sockaddr_storage>()) should be fine. But in the implementation, both AF_INET and AF_INET6 assert that the size passed is exactly size_of::<sockaddr_in>()/size_of::<sockaddr_in6>(). Ideally IMO the implementation would match the documented behavior.

@asomers
Copy link
Member

asomers commented Aug 9, 2021

Yes, I think you're probably right. Doing it as documented shouldn't lead to a memory leak. But do you have any examples of something that creates a sockaddr_in or sockaddr_in6 as a sockaddr_storage with too much space?

@khuey
Copy link
Contributor Author

khuey commented Aug 9, 2021

When doing strace-like things it's convenient to grab size_of::<sockaddr_storage>() bytes of data and then have the function just work.

@asomers
Copy link
Member

asomers commented Aug 9, 2021

That makes sense. Care to submit a patch?

@khuey
Copy link
Contributor Author

khuey commented Aug 9, 2021

When I have a chance, sure.

bors bot added a commit that referenced this issue Aug 18, 2021
1486: Relax assertions in sockaddr_storage_to_addr to match the documentation. r=asomers a=khuey

Fixes #1479

1490: add libc::IP6T_SO_ORIGINAL_DST to socket opt r=asomers a=bearice

the original PR #1410 was stalled for a while
let's make it happen.

this should closes #1410 and #938

1493: Fix crates.io badge r=asomers a=atouchet



Co-authored-by: Kyle Huey <khuey@kylehuey.com>
Co-authored-by: Icemic <bingfeng.web@gmail.com>
Co-authored-by: Bearice Ren <bearice@icybear.net>
Co-authored-by: Alex Touchet <alextouchet@outlook.com>
bors bot added a commit that referenced this issue Aug 18, 2021
1486: Relax assertions in sockaddr_storage_to_addr to match the documentation. r=asomers a=khuey

Fixes #1479

Co-authored-by: Kyle Huey <khuey@kylehuey.com>
bors bot added a commit that referenced this issue Aug 18, 2021
1486: Relax assertions in sockaddr_storage_to_addr to match the documentation. r=asomers a=khuey

Fixes #1479

1490: add libc::IP6T_SO_ORIGINAL_DST to socket opt r=asomers a=bearice

the original PR #1410 was stalled for a while
let's make it happen.

this should closes #1410 and #938

1493: Fix crates.io badge r=asomers a=atouchet



Co-authored-by: Kyle Huey <khuey@kylehuey.com>
Co-authored-by: Icemic <bingfeng.web@gmail.com>
Co-authored-by: Bearice Ren <bearice@icybear.net>
Co-authored-by: Alex Touchet <alextouchet@outlook.com>
@bors bors bot closed this as completed in d133d3d Aug 18, 2021
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 a pull request may close this issue.

2 participants