Skip to content

Commit

Permalink
connectd: fix valgrind complaint on FreeBSD
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Dec 7, 2020
1 parent 4507203 commit 089ecfe
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions connectd/netaddress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down

0 comments on commit 089ecfe

Please sign in to comment.