From: Ally Sommers dropbear.sh@gmail.com
This also introduces an error when attempting to create an AF_UNIX socket of type SOCK_DGRAM. --- server/sock.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/server/sock.c b/server/sock.c index d1ab7ad7cd8..59b2e84b926 100644 --- a/server/sock.c +++ b/server/sock.c @@ -1880,6 +1880,12 @@ static int init_socket( struct sock *sock, int family, int type, int protocol ) return -1; }
+ if (unix_family == AF_UNIX && unix_type == SOCK_DGRAM) + { + set_win32_error(WSAEAFNOSUPPORT); + return -1; + } + sockfd = socket( unix_family, unix_type, unix_protocol );
#ifdef linux @@ -2638,18 +2644,29 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) if (unix_addr.addr.sa_family == AF_INET && !memcmp( &unix_addr.in.sin_addr, magic_loopback_addr, 4 )) unix_addr.in.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
- if (sock->family == WS_AF_UNIX && *((struct WS_sockaddr_un *)&addr)->sun_path) + if (sock->family == WS_AF_UNIX) { - char *unix_path = (char *)(params + 1) + params->addr_len; - char unix_path_copy[PATH_MAX]; - send_len -= strlen( unix_path ) + 1; - strcpy(unix_path_copy, unix_path); - if (chdir( dirname( unix_path_copy ) ) == -1) + if (*((struct WS_sockaddr_un *)&addr)->sun_path) { - set_error( sock_get_ntstatus( errno ) ); + char *unix_path = (char *)(params + 1) + params->addr_len; + char unix_path_copy[PATH_MAX]; + send_len -= strlen( unix_path ) + 1; + strcpy(unix_path_copy, unix_path); + if (chdir( dirname( unix_path_copy ) ) == -1) + { + set_error( sock_get_ntstatus( errno ) ); + return; + } + memcpy( unix_addr.un.sun_path, basename( unix_path ), sizeof(unix_addr.un.sun_path) ); + } + else + { + /* Contrary to documentation, Windows does not currently support abstract Unix + * sockets. connect() throws WSAEINVAL if sun_family is AF_UNIX and sun_path + * begins with '\0', even though bind() will succeed. */ + set_win32_error( WSAEINVAL ); return; } - memcpy( unix_addr.un.sun_path, basename( unix_path ), sizeof(unix_addr.un.sun_path) ); }
ret = connect( unix_fd, &unix_addr.addr, unix_len );