]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
socket: zero sockaddr_un to initialize sa_len
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 16 Dec 2021 09:41:31 +0000 (10:41 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 16 Dec 2021 09:48:31 +0000 (10:48 +0100)
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

index 860fa0f2642e1d78833391587edfdc6201f760df..8a5d046802a938a819cc7c7e91378c6cb1dc2e8f 100644 (file)
--- 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);