Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220825025859.GC1923@voyager>
Date: Thu, 25 Aug 2022 04:58:59 +0200
From: Markus Wichmann <nullplan@....net>
To: musl@...ts.openwall.com
Subject: Re: IPv4 fallback in __res_msend_rc not functional

On Wed, Aug 24, 2022 at 07:32:28PM -0400, Rich Felker wrote:
> Does this work?
>
> diff --git a/src/network/res_msend.c b/src/network/res_msend.c
> index 3e018009..105bf598 100644
> --- a/src/network/res_msend.c
> +++ b/src/network/res_msend.c
> @@ -68,14 +68,15 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
>  	}
>
>  	/* Get local address and open/bind a socket */
> -	sa.sin.sin_family = family;
>  	fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
>
>  	/* Handle case where system lacks IPv6 support */
>  	if (fd < 0 && family == AF_INET6 && errno == EAFNOSUPPORT) {
>  		fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
>  		family = AF_INET;
> +		sl = sizeof sa.sin;
>  	}
> +	sa.sin.sin_family = family;
>  	if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) {
>  		if (fd >= 0) close(fd);
>  		pthread_setcancelstate(cs, 0);
>

That would have been my proposal as well, although I would have added a
"if (ns[j].sin.sin_family == family)" in front of the sendto call as
well.

Another question to think about is if the function should terminate
early if there are no usable servers in the config. Without the IPv4
fallback, this could only happen with conf->nns == 0, but with it, it
can also happen when all configured servers are IPv6 and IPv6 is
unusable (which the callers can't know). In that case, the function
would now not send anything (as sendto() fails silently), and wait in
vain for a response.

Ciao,
Markus

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.