[ccan] [PATCH] net: fix tests on hosts where 'localhost' is v4 _and_ v6

Sam Vilain sam at vilain.net
Tue Feb 8 06:55:30 EST 2011


On 07/02/11 17:32, Rusty Russell wrote:
> Unfortunately your patch broke my setup, which says to me that it's
> time to
> invoke The Elements of Programming Style and rewrite it.
>
> This tries to even handle the future IPv6 only case, on top of your patch.

A host with only v6 networking?  Yeah right!  ;-)

Tests like this are always going to be a bit dodgy, you have to make
assumptions which are not guaranteed.  v6 defines localhost at least
conceptually as ::1, whereas in v4 it could have been anywhere under
127.0/8; it used to break Perl's networking test cases when they assumed
they could listen on 127.1 and localhost was running on a different IP
to that.

> Does it work for you?

Yes, I've checked this with a number of configurations of /etc/hosts.

>  static void double_addr_free(struct addrinfo* addr)
> @@ -84,7 +98,7 @@ static void double_addr_free(struct addrinfo* addr)
>  	}
>  	freeaddrinfo(addr);
>  	if (we_faked_double)
> -		freeaddrinfo(addr);
> +		freeaddrinfo(addr2);
>  }

How did I manage to write a double free into a function I so carefully
avoided calling "double_free_addr" ?  *sigh*

Sam


More information about the ccan mailing list