]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: fix transmit_reply() to not read uninitialized data
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 16 Dec 2021 10:36:26 +0000 (11:36 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 16 Dec 2021 10:49:15 +0000 (11:49 +0100)
In the FreeBSD-specific code checking for a bound IPv4 socket, make
sure it is not a Unix domain address to avoid reading uninitialized
IP-specific fields.

This fixes an error reported by valgrind.

cmdmon.c

index cd064707495c236d0b58b104571b7c58f69afa19..89f5b95d68a1c0468a006a45d5137d2d3d9d8232 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -321,7 +321,8 @@ transmit_reply(int sock_fd, int request_length, SCK_Message *message)
 
 #if !defined(HAVE_IN_PKTINFO) && defined(IP_SENDSRCADDR)
   /* On FreeBSD a local IPv4 address cannot be specified on bound socket */
-  if (message->local_addr.ip.family == IPADDR_INET4 && (sock_fd != sock_fd4 || bound_sock_fd4))
+  if (message->addr_type == SCK_ADDR_IP && message->local_addr.ip.family == IPADDR_INET4 &&
+      (sock_fd != sock_fd4 || bound_sock_fd4))
     message->local_addr.ip.family = IPADDR_UNSPEC;
 #endif