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
2ad2316d32
commit
073a59264a
3 changed files with 8 additions and 3 deletions
|
@ -327,7 +327,7 @@ set(PACKAGE "libwebsockets")
|
|||
set(CPACK_PACKAGE_NAME "${PACKAGE}")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "4")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "0")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "9")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "10")
|
||||
set(CPACK_PACKAGE_RELEASE 1)
|
||||
set(CPACK_GENERATOR "RPM")
|
||||
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -644,7 +644,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