From 089ecfe4189efca117e356ff88ec59f33f0b4f75 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 7 Dec 2020 09:46:39 +1030 Subject: [PATCH] connectd: fix valgrind complaint on FreeBSD As reported by Wladimir J. van der Laan. Valgrind will complain about padding and unset fields, so memset the structs. ``` ==42653== Syscall param socketcall.connect(serv_addr..sa_len) points to uninitialised byte(s) ==42653== at 0x4C7D19A: _connect (in /lib/libc.so.7) ==42653== by 0x4EE1F35: ??? (in /lib/libthr.so.3) ==42653== by 0x249D57: get_local_sockname (netaddress.c:212) ==42653== by 0x249CDB: guess_address (netaddress.c:242) ==42653== by 0x2473D0: public_address (connectd.c:1003) ==42653== by 0x246CE4: setup_listeners (connectd.c:0) ==42653== by 0x246566: connect_init (connectd.c:1311) ==42653== by 0x270CEB: next_plan (io.c:59) ==42653== by 0x2713EE: io_ready (io.c:417) ==42653== by 0x2726B1: io_loop (poll.c:445) ==42653== by 0x24618A: main (connectd.c:1703) ==42653== Address 0x7fc000690 is on thread 1's stack ==42653== in frame #3, created by guess_address (netaddress.c:231) ``` Signed-off-by: Rusty Russell --- connectd/netaddress.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/connectd/netaddress.c b/connectd/netaddress.c index 12b50f2f7713..91f07ee48952 100644 --- a/connectd/netaddress.c +++ b/connectd/netaddress.c @@ -235,6 +235,7 @@ bool guess_address(struct wireaddr *addr) switch (addr->type) { case ADDR_TYPE_IPV4: { struct sockaddr_in sin; + memset(&sin, 0, sizeof(sin)); sin.sin_port = htons(53); /* 8.8.8.8 */ sin.sin_addr.s_addr = 0x08080808; @@ -246,6 +247,7 @@ bool guess_address(struct wireaddr *addr) } case ADDR_TYPE_IPV6: { struct sockaddr_in6 sin6; + memset(&sin6, 0, sizeof(sin6)); /* 2001:4860:4860::8888 */ static const unsigned char pchGoogle[16] = {0x20,0x01,0x48,0x60,0x48,0x60,0,0,0,0,0,0,8,8,8,8};