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

Set correct sockaddr length for abstract addresses #374

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Network/Socket/Types.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,10 @@ type CSaFamily = (#type sa_family_t)
-- in that the value of the argument /is/ used.
sizeOfSockAddr :: SockAddr -> Int
#if defined(DOMAIN_SOCKET_SUPPORT)
sizeOfSockAddr SockAddrUnix{} = #const sizeof(struct sockaddr_un)
sizeOfSockAddr (SockAddrUnix path) =
case path of
'\0':_ -> (#const sizeof(sa_family_t)) + length path

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 Chars to CChars. Using ByteString here would have been a better interface. ]

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.

_ -> #const sizeof(struct sockaddr_un)
#else
sizeOfSockAddr SockAddrUnix{} = error "sizeOfSockAddr: not supported"
#endif
Expand Down