summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2024-05-17 14:52:46 +0200
committerJo-Philipp Wich <jo@mein.io>2024-05-17 15:31:56 +0200
commit525fca2240123d65f8bc13b1ef7e36988e62128f (patch)
treec7e6f2863586ac6b2a8e88121ff1a81131a723e7 /lib
parent36f106056069d545b63041533ba22c391b05e119 (diff)
socket: uv_to_sockaddr(): fix length calculation for AF_UNIX addresses
Do not attempt to calculate a dynamic length for AF_UNIX socket addresses but return the total size of `struct sockaddr_un`, like we do it for the structures of other address families as well. Fixes incorrect domain socket path truncation. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/socket.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/socket.c b/lib/socket.c
index 5ef3a1e..cf7b6aa 100644
--- a/lib/socket.c
+++ b/lib/socket.c
@@ -481,14 +481,13 @@ uv_to_sockaddr(uc_value_t *addr, struct sockaddr_storage *ss, socklen_t *slen)
len = ucv_string_length(addr);
if (memchr(s, '/', len) != NULL) {
- *slen = ucv_string_length(addr);
+ if (len >= sizeof(su->sun_path))
+ len = sizeof(su->sun_path) - 1;
- if (*slen >= sizeof(su->sun_path))
- *slen = sizeof(su->sun_path) - 1;
-
- memcpy(su->sun_path, s, *slen);
- su->sun_path[(*slen)++] = 0;
+ memcpy(su->sun_path, s, len);
+ su->sun_path[len++] = 0;
su->sun_family = AF_UNIX;
+ *slen = sizeof(*su);
ok_return(true);
}
@@ -678,7 +677,7 @@ uv_to_sockaddr(uc_value_t *addr, struct sockaddr_storage *ss, socklen_t *slen)
memcpy(su->sun_path, ucv_string_get(item), len);
su->sun_path[len++] = 0;
su->sun_family = AF_UNIX;
- *slen = len;
+ *slen = sizeof(*su);
ok_return(true);