From fb0570cc737169bea5d6d4d7e5b241195b2b7dbc Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 16 Dec 2021 10:41:31 +0100 Subject: [PATCH] socket: zero sockaddr_un to initialize sa_len Zero the whole sockaddr struct before calling bind() and connect() to initialize the FreeBSD-specific sa_len field. This fixes errors reported by valgrind. --- socket.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/socket.c b/socket.c index 860fa0f..8a5d046 100644 --- a/socket.c +++ b/socket.c @@ -505,6 +505,8 @@ bind_unix_address(int sock_fd, const char *addr, int flags) { union sockaddr_all saddr; + memset(&saddr, 0, sizeof (saddr)); + if (snprintf(saddr.un.sun_path, sizeof (saddr.un.sun_path), "%s", addr) >= sizeof (saddr.un.sun_path)) { DEBUG_LOG("Unix socket path %s too long", addr); @@ -537,6 +539,8 @@ connect_unix_address(int sock_fd, const char *addr) { union sockaddr_all saddr; + memset(&saddr, 0, sizeof (saddr)); + if (snprintf(saddr.un.sun_path, sizeof (saddr.un.sun_path), "%s", addr) >= sizeof (saddr.un.sun_path)) { DEBUG_LOG("Unix socket path %s too long", addr);