mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
unix domain: fix path name length
Unlike any other sockaddr variant it turns out when sockaddr_un reports its sizeof() to connect() or listen(), it is trimmed to the used length of the sun_path[] member not including any trailing 0x00. Until now we worked fine, but our actual UDS paths have a large number of trailing 0x00 (shown as @ in most tools). Clients and servers can still interoperate if they both have this broken name. This patch fixes it to trim the sockaddr_un to the path length so the name is as you would expect.
This commit is contained in:
parent
280c81278d
commit
d7ac7f4deb
2 changed files with 7 additions and 2 deletions
|
@ -215,7 +215,6 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port,
|
|||
#if defined(LWS_WITH_UNIX_SOCK)
|
||||
if (!port && LWS_UNIX_SOCK_ENABLED(vhost)) {
|
||||
v = (struct sockaddr *)&serv_unix;
|
||||
n = sizeof(struct sockaddr_un);
|
||||
memset(&serv_unix, 0, sizeof(serv_unix));
|
||||
serv_unix.sun_family = AF_UNIX;
|
||||
if (!iface)
|
||||
|
@ -225,12 +224,15 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port,
|
|||
iface);
|
||||
return LWS_ITOSA_NOT_EXIST;
|
||||
}
|
||||
n = sizeof(uint16_t) + strlen(iface);
|
||||
strcpy(serv_unix.sun_path, iface);
|
||||
if (serv_unix.sun_path[0] == '@')
|
||||
serv_unix.sun_path[0] = '\0';
|
||||
else
|
||||
unlink(serv_unix.sun_path);
|
||||
|
||||
// lwsl_hexdump_notice(v, n);
|
||||
|
||||
} else
|
||||
#endif
|
||||
#if defined(LWS_WITH_IPV6) && !defined(LWS_PLAT_FREERTOS)
|
||||
|
|
|
@ -684,7 +684,10 @@ ads_known:
|
|||
#if defined(LWS_WITH_UNIX_SOCK)
|
||||
if (wsi->unix_skt) {
|
||||
psa = (const struct sockaddr *)&sau;
|
||||
n = sizeof(sau);
|
||||
if (sau.sun_path[0])
|
||||
n = sizeof(uint16_t) + strlen(sau.sun_path);
|
||||
else
|
||||
n = sizeof(uint16_t) + strlen(&sau.sun_path[1]) + 1;
|
||||
} else
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue