-
Notifications
You must be signed in to change notification settings - Fork 188
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
Set correct sockaddr length for abstract addresses #374
Conversation
Relating to #306 |
@vdukhovni @JonCoens Could you review this PR? |
sizeOfSockAddr SockAddrUnix{} = #const sizeof(struct sockaddr_un) | ||
sizeOfSockAddr (SockAddrUnix path) = | ||
case path of | ||
'\0':_ -> (#const sizeof(sa_family_t)) + length path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The abstract sockets are a Linux-specific feature. Should support for this also be Linux-specific? Is there any evidence of support for such unix-domain sockets on any of the BSDs, or other unix-like system?
[ By the way, it is rather unfortunate that the path
associated with a unix-domain socket SockAddrUnix
is a String
and not a ByteString
. Calling length
here is only correct, because when binding the socket we later truncate all the Char
s to CChar
s. Using ByteString
here would have been a better interface. ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also at around line 1019, I don't see any effort to decode abstract socket addresses correctly. Is there a portable way to distinguish empty paths from abstract socket addresses? Presently it looks like they'll return an empty path from accept()
, getsockname()
and getpeername()
. If these are to be supported, surely not just connect()
, sendto()
and bind()
should work, but also accept()
, getsockname()
, getpeername
and recvfrom()
for datagram sockets.
Gentle ping. |
Will you be addressing the review comments? |
I'm just reverting parts of the #306 which broke things. This change would unbreak abstract sockets support and enable dbus library builds with the latest network versions. If there was no support for getting proper addresses (I checked), I feel adding new features is out of scope for this diff. |
If abstract sockets are supported, they need to work correctly. Making them work not only for the system calls that take addresses, but also for the system-calls that return addresses is not a new feature. Also if the abstract sockets are Linux-specific, then the logic to support them needs to be specific to Linux, lest it break other platforms. Once you open the can of worms you should deal with all the issues that present themselves, leaving the code in a known correct state. |
Some tests of support for abstract sockets would also reduce opportunities for future regressions. |
I fully support adding tests. I'd love to land #375 before that, since it is causing a lot of churn in the test modules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add #ifdef
Merged. |
@kazu-yamamoto Thank you! This works just fine. |
There are three types of unix sockets [in Linux]: pathname, unnamed and abstract, see unix(7) for details. It is okay to use long sockaddr len with the pathname, which is null-terminated, and unnamed, which has no name.
But sun_path in the abstract sockaddr is effectively a blob, and sockaddr length must be set correctly. Otherwise, the connection fails.
Good strace:
Bad strace: