Skip to content

recvfrom: don't convert address if addrsize is 0 #1153

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

Merged
merged 3 commits into from
May 3, 2024
Merged

Conversation

G4Vi
Copy link
Collaborator

@G4Vi G4Vi commented Apr 23, 2024

Fix malformed address from being returned from recvfrom on connection oriented sockets: pass through addrsize when it's 0. Additionally, set addrsize to 0 when it is unchanged as win32 recvfrom does not set addrsize on connection sockets.

This behavior is not required by POSIX, but observed on at least "Linux, OS/X and OpenBSD" so I think we should adapt this behavior.

Perl depends on either this behavior or returning getpeername. To work around win32 recvfrom with Cygwin it sets addrsize to 0 when addrsize is unchanged:
Perl/perl5@e122534#diff-400754cb38a9f79143e9a5b9248562cfde2ec692b374136149a4bef3d0fdbbac. For Win32 directly, it returns getpeername when size is unchanged: https://github.com/Perl/perl5/blob/8c2652c1d9709e58ccf726121d1d7bb04c96b354/win32/win32sck.c#L427-L441

Perl's t/io/socket.t expects recvfrom to return a 0 length src address when called on a PF_INET socket.

Perl/perl5#13101

ALSO, looking at recvfrom_test.c I'm not sure why other test was set to only run on Windows. I tested my new test on Windows and Linux.

Fixes malformed address being returned for recvfrom on connection oriented sockets.
@G4Vi G4Vi marked this pull request as draft April 23, 2024 03:17
@G4Vi G4Vi marked this pull request as ready for review April 24, 2024 01:56
@G4Vi G4Vi marked this pull request as draft May 3, 2024 06:59
@G4Vi G4Vi marked this pull request as ready for review May 3, 2024 14:37
@G4Vi G4Vi requested review from mrdomino and ahgamut May 3, 2024 14:38
Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

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

Thanks!

@jart jart merged commit deff138 into jart:master May 3, 2024
@G4Vi G4Vi deleted the fix-recvfrom branch May 14, 2024 04:06
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