Skip to content

Conversation

@mmeyer724
Copy link
Contributor

@mmeyer724 mmeyer724 commented Jul 25, 2018

On MacOS 10.14 w/PHP 7.2.8, I am unable to send data between two unix datagram sockets due to a bug in PHP's socket_recvfrom implementation. This bug caused the path/name of the sender to come back with trailing garbage bytes at the end of the string.

This appears to be caused by a failure to initialize struct sockaddr_un s_un; to 0 before passing it into recvfrom. This pull requests simply adds a memset to set the memory to 0 first.

Sample output from my program before:

Received 'Ping' from '/tmp/mysockclient.sock@c�'

Sample output with this fix in place:

Received 'Ping' from '/tmp/mysockclient.sock'

Note: This script runs fine on Ubuntu 16.04 using the stock php package, so I'm assuming this bug only affects MacOS.

@bukka
Copy link
Member

bukka commented Aug 5, 2018

It looks reasonable. Would you be able to add a test for this? And pls could you open a bug?

I also checked the code a little bit and it seems that it might also overflow in socket_sendto fom long paths on mac in here:

https://github.com/mmeyer724/php-src/blob/1f7ee2f69591abec1c224ae75f2a750ef860bc4f/ext/sockets/sockets.c#L1926

I might be wrong but it seems that sun_path is hard coded to 108 and the osx limit is 104: https://developer.apple.com/documentation/kernel/sockaddr_un/1541426-sun_path?language=objc

Anyway it's a different issue so not really related to this one...

@krakjoe
Copy link
Member

krakjoe commented Sep 4, 2018

@mmeyer724 any action here ?

@mmeyer724
Copy link
Contributor Author

@krakjoe Sorry I forgot about this! I'm working on bukka's feedback now

@mmeyer724
Copy link
Contributor Author

mmeyer724 commented Sep 4, 2018

@bukka Sorry for the delay, would you mind checking out the .phpt test I just pushed? :-)
Link to the bug I created: https://bugs.php.net/bug.php?id=76839

@mmeyer724
Copy link
Contributor Author

For what it's worth, I'm pretty sure the appveyor build failures are unrelated to my changes here. 😕

@bukka
Copy link
Member

bukka commented Sep 6, 2018

LGTM

@KalleZ
Copy link
Member

KalleZ commented Sep 6, 2018

What is the reason that Windows is skipped here? I'm not too familiar with the socket code but I did not see any obvious places for anything not implemented on Windows in the surrounding blocks?

@mmeyer724
Copy link
Contributor Author

@KalleZ I initially wrote the test without the windows exclusion, but it failed hard in the CI pipeline. As far as I can tell AF_UNIX sockets are not supported on Windows (or at least they're not supported on the version of windows appveyor is using: https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows)

@KalleZ
Copy link
Member

KalleZ commented Sep 7, 2018

Aha thanks, that clears it up a little! I was just curious given we don't have any surrounding guards for the AF_UNIX blocks in the code. Perhaps thats something we should look into, but that can wait for another issue.

Alternatively you can use the userland constants ''PHP_WINDOWS_XXX'' to see if the version of Windows supports like:

if(PHP_OS_FAMILY == 'Windows' && (PHP_WINDOWS_VERSION_MAJOR < 10 || (PHP_VERSION_MAJOR === 10 && PHP_VERSION_BUILD < 17063))) { die('skip: This test requires Windows 10, build 17063 or greater'); }

(Keep in mind its just a pseudo)

@weltling
Copy link
Contributor

For what i'd care, this patch is fine. Unix socket supprot on Windows needs to be yet revisited and enabled/completed including tests. The patch seems to be fine for now for 7.2 as well.

Thanks.

@weltling
Copy link
Contributor

Merged as 3c42c78.

Thanks

@weltling weltling closed this Dec 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants